diff --git a/commands/PackageController.php b/commands/PackageController.php new file mode 100644 index 0000000..410f279 --- /dev/null +++ b/commands/PackageController.php @@ -0,0 +1,22 @@ +all(); + foreach ($packages as $package) { + $package->bower = Git::get($package->url, 'bower.json'); + $package->save(); + } + } + +} diff --git a/components/Git.php b/components/Git.php new file mode 100644 index 0000000..07ad570 --- /dev/null +++ b/components/Git.php @@ -0,0 +1,54 @@ + 'https://raw.', + '.git' => '/master/' . $file, + ]); + return @file_get_contents($https); + } + + /** + * @param $endpoint + * @param $file + * @return string + */ + private static function getBitBucket($endpoint, $file) + { + $https = strtr($endpoint, [ + 'git://' => 'https://', + '.git' => '/raw/master/' . $file, + ]); + return @file_get_contents($https); + } +} \ No newline at end of file diff --git a/config/bootstrap.php b/config/bootstrap.php new file mode 100644 index 0000000..a4abe2d --- /dev/null +++ b/config/bootstrap.php @@ -0,0 +1,2 @@ + 'minetest-bower', @@ -6,6 +7,11 @@ $config = [ 'basePath' => dirname(__DIR__), 'components' => [ 'db' => require(__DIR__ . '/db.php'), + ], +]; + +$web = [ + 'components' => [ 'errorHandler' => [ 'errorAction' => 'site/error', ], @@ -25,4 +31,16 @@ $config = [ ], ]; -return $config; +$console = [ + 'controllerNamespace' => 'app\commands', +]; + +if (php_sapi_name() != 'cli') { + // Web application + $config = ArrayHelper::merge($config, $web); +} else { + // Console application + $config = ArrayHelper::merge($config, $console); +} + +return $config; \ No newline at end of file diff --git a/controllers/PackageController.php b/controllers/PackageController.php index 641026c..fd58bd2 100644 --- a/controllers/PackageController.php +++ b/controllers/PackageController.php @@ -2,6 +2,7 @@ namespace app\controllers; +use app\components\Git; use app\models\Package; use Yii; use yii\filters\VerbFilter; @@ -31,6 +32,36 @@ class PackageController extends Controller return parent::beforeAction($action); } + public function actionIndex() + { + return Package::find() + ->select(['name', 'url', 'hits']) + ->orderBy(['hits' => SORT_DESC]) + ->all(); + } + + public function actionView($name) + { + $package = Package::find() + ->where(['name' => $name]) + ->one(); + if ($package) { + $package->hits++; + $package->save(); + return $package; + } + throw new HttpException(404, 'Package not found.'); + } + + public function actionSearch($name) + { + return Package::find() + ->select(['name', 'url', 'hits']) + ->where(['like', 'name', $name]) + ->orderBy(['hits' => SORT_DESC]) + ->all(); + } + public function actionCreate() { $package = new Package(); @@ -47,7 +78,7 @@ class PackageController extends Controller } } if (isset($package->errors['name'])) { - throw new HttpException(400, 'Invalid Package Name: ' . implode(', ', $package->errors['name'])); + throw new HttpException(400, 'Invalid Name: ' . implode(', ', $package->errors['name'])); } if (isset($package->errors['url'])) { throw new HttpException(400, 'Invalid URL: ' . implode(', ', $package->errors['url'])); @@ -61,25 +92,4 @@ class PackageController extends Controller throw new HttpException(400, 'Error: ' . implode(', ', $errors)); } - public function actionIndex() - { - return Package::find()->orderBy(['hits' => SORT_DESC])->all(); - } - - public function actionView($name) - { - $package = Package::find()->where(['name' => $name])->one(); - if ($package) { - $package->hits++; - $package->save(); - return $package; - } - throw new HttpException(404); - } - - public function actionSearch($name) - { - return Package::find()->where(['like', 'name', $name])->orderBy(['hits' => SORT_DESC])->all(); - } - } diff --git a/migrations/m150808_000001_create_package.php b/migrations/m150808_000001_create_package.php index 1462f00..c1ca862 100644 --- a/migrations/m150808_000001_create_package.php +++ b/migrations/m150808_000001_create_package.php @@ -14,6 +14,7 @@ class m150808_000001_create_package extends Migration 'name' => Schema::TYPE_STRING . '(128) NOT NULL', 'url' => Schema::TYPE_STRING . '(255) NOT NULL', 'hits' => Schema::TYPE_INTEGER . ' NOT NULL', + 'bower' => Schema::TYPE_TEXT, 'created_at' => Schema::TYPE_TIMESTAMP . ' NOT NULL', 'updated_at' => Schema::TYPE_TIMESTAMP . ' NOT NULL', ], ($this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB' : null)); diff --git a/models/Package.php b/models/Package.php index 79ccd79..101ad21 100644 --- a/models/Package.php +++ b/models/Package.php @@ -2,8 +2,10 @@ namespace app\models; +use app\models\query\PackageQuery; use Yii; use yii\behaviors\TimestampBehavior; +use yii\db\ActiveRecord; /** * This is the model class for table "{{%package}}". @@ -12,10 +14,11 @@ use yii\behaviors\TimestampBehavior; * @property string $name * @property string $url * @property integer $hits + * @property string $bower * @property string $created_at * @property string $updated_at */ -class Package extends \yii\db\ActiveRecord +class Package extends ActiveRecord { /** * @inheritdoc @@ -49,6 +52,7 @@ class Package extends \yii\db\ActiveRecord 'name' => 'Name', 'url' => 'URL', 'hits' => 'Hits', + 'bower' => 'Bower', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; @@ -68,4 +72,13 @@ class Package extends \yii\db\ActiveRecord ], ]; } + + /** + * @inheritdoc + * @return PackageQuery the active query used by this AR class. + */ + public static function find() + { + return new PackageQuery(get_called_class()); + } } diff --git a/models/query/PackageQuery.php b/models/query/PackageQuery.php new file mode 100644 index 0000000..715f99a --- /dev/null +++ b/models/query/PackageQuery.php @@ -0,0 +1,30 @@ +params['jumbotron'] = '/site/_index-jumbotron';

Create Packages

Create packages with bower register.

-
$ bower register <name> <url>
+                
$ bower register <my_mod_name> <git_endpoint>
 
-$ bower register mymod git://github.com/username/mymod.git
+# for example +$ bower register example git://github.com/user/example.git