Skip to content

Commit

Permalink
+ search. it all works now
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Apr 25, 2016
1 parent f9c3cb1 commit 01d5501
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
'controllerNamespace' => 'hiqdev\assetpackagist\controllers',
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'storage' => dirname(dirname(__DIR__)) . '/web',
'npm' => '@vendor/npm-asset',
'bower' => '@vendor/bower-asset',
],
'components' => [
'log' => [
Expand Down
2 changes: 1 addition & 1 deletion src/config/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

return [
'aliases' => [
'@web' => '@prjdir/web',
'storage' => dirname(dirname(__DIR__)) . '/web',
],
];
1 change: 0 additions & 1 deletion src/console/AssetPackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace hiqdev\assetpackagist\console;

use hiqdev\assetpackagist\models\AssetPackage;

use Yii;

class AssetPackageController extends \yii\console\Controller
Expand Down
16 changes: 16 additions & 0 deletions src/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace hiqdev\assetpackagist\controllers;

use hiqdev\assetpackagist\models\AssetPackage;
use Yii;

class SiteController extends \yii\web\Controller
{
public function actionIndex()
Expand All @@ -27,4 +30,17 @@ public function actionContact()
{
return $this->render('contact');
}

public function actionSearch()
{
$q = Yii::$app->request->get('query') ?: Yii::$app->request->post('query');
list($temp, $name) = explode('/', $q);
list($type, $temp) = explode('-', $temp);
$package = new AssetPackage($type, $name);
$binpath = Yii::getAlias('@vendor/bin/hidev');
system("$binpath asset-package/update $type $name");
$package->load();

return $this->render('search', compact('package'));
}
}
21 changes: 20 additions & 1 deletion src/models/AssetPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace hiqdev\assetpackagist\models;

use hiqdev\assetpackagist\registry\RegistryFactory;
use Exception;
use Composer\Factory;
use Composer\IO\NullIO;
use hiqdev\assetpackagist\registry\RegistryFactory;

class AssetPackage
{
Expand All @@ -22,10 +23,26 @@ class AssetPackage

public function __construct($type, $name)
{
if (!$this->checkType($type)) {
throw new Exception('wrong type');
}
if (!$this->checkName($name)) {
throw new Exception('wrong name');
}
$this->_type = $type;
$this->_name = $name;
}

public function checkType($type)
{
return $type === 'bower' || $type === 'npm';
}

public function checkName($name)
{
return strlen($name)>1;
}

public function getFullName()
{
return static::buildFullName($this->_type, $this->_name);
Expand Down Expand Up @@ -55,6 +72,8 @@ static public function getCommonComposer()
{
if (static::$_commonComposer === null) {
static::$_commonComposer = Factory::create(new NullIO());
#$factory = new Factory();
#static::$_commonComposer = $factory->createComposer(new NullIO(), null, false, null, false);
}

return static::$_commonComposer;
Expand Down
2 changes: 1 addition & 1 deletion src/models/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Storage

protected function __construct()
{
$this->_path = Yii::getAlias('@web');
$this->_path = Yii::getAlias('@storage');
}

static public function getInstance()
Expand Down
2 changes: 1 addition & 1 deletion src/views/layouts/_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<br><br><br>
<div class="container">
<div class="col-xs-12 col-md-9" style="padding:0px 0 10px 0">
<form name="search_query" method="get" action="/search/" id="search-form" autocomplete="off">
<form name="search_query" method="get" action="/site/search" id="search-form" autocomplete="off">
<input type="search" id="query" name="query" required="required" autocomplete="off" placeholder="bower-asset/package-name" tabindex="1" class="form-control"/>
</form>
</div>
Expand Down
24 changes: 24 additions & 0 deletions src/views/site/search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/* @var $this yii\web\View */

use yii\helpers\Html;

$this->title = 'Search';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
<h1><?= Html::encode($package->getFullName()) ?></h1>

<p>
<?php $releases = (array)$package->getReleases() ?>
<table>
<?php foreach ($releases as $version => $release) : ?>
<tr>
<th><?= $version ?></th>
<td><code><?= $release['source']['reference'] ?: $release['dist']['reference'] ?></code></td>
</tr>
<?php endforeach ?>
</table>
</p>
</div>

0 comments on commit 01d5501

Please sign in to comment.