Skip to content

Commit

Permalink
Merge branch 'release/v1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy IIIFX Khomenko committed Jan 17, 2017
2 parents cdd8ff9 + 9ca6bd2 commit fe2a9c5
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 64 deletions.
8 changes: 4 additions & 4 deletions README.RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Используя Composer:

```bash
composer require "iiifx-production/yii2-autocomplete-helper:v1.*"
composer require "iiifx-production/yii2-autocomplete-helper:^1.1"
```

## Настройка
Expand Down Expand Up @@ -147,7 +147,7 @@ php yii my-custom-generator
]
```

Важно понимать, что путь к файлу автодополнения используется относительно пути **@app** в фреймворке, потому для Yii2 Advanced путь должен содержать "..". Пример: **@console/../new-file-name.php**.
Путь к файлу должен быть указан относительно алиасов фреймворка. Пример: **@common/../new-file-name.php**.

### Особые файлы конфигурации

Expand Down Expand Up @@ -217,8 +217,8 @@ php yii my-custom-generator
'api' => [
'@common/config/main.php', # <-- группа для api
'@common/config/main-local.php',
'@api/config/main.php',
'@api/config/main-local.php',
'@common/../api/config/main.php',
'@common/../api/config/main-local.php',
],
],
],
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This extension allows you to automatically generate a file with the autocomplete
Using Composer:

```bash
composer require "iiifx-production/yii2-autocomplete-helper:v1.*"
composer require "iiifx-production/yii2-autocomplete-helper:^1.1"
```

## Configuration
Expand Down Expand Up @@ -61,7 +61,7 @@ Vitaliy IIIFX Khomenko (c) 2016

Success: /domains/project.local/_ide_components.php
```
**Important:** For IDE did not swear on the two copies of the Yii class must be main Yii class file marked as a text document - [example](images/mark-as-plain-text.png).
**Important:** For IDE did not swear on the two copies of the Yii class must be main Yii class file marked as a text document - [example](images/mark-as-plain-text.png).
The main class is located on the way: **@vendor/yiisoft/yii2/Yii.php**

## Advanced customization
Expand Down Expand Up @@ -146,7 +146,7 @@ You can change the name and location of the file:
]
```

It is important to understand that the path to the file used **@app** in the framework, because for Yii2 Advanced path must contain "..". Example: **@console/../new-file-name.php**.
The file path must be relative to aliases framework. Example: **@common/../new-file-name.php**.

### Special configuration files

Expand Down Expand Up @@ -216,16 +216,16 @@ You can group configuration files and generate autocompletion only for a specifi
'api' => [
'@common/config/main.php', # <-- api group
'@common/config/main-local.php',
'@api/config/main.php',
'@api/config/main-local.php',
'@common/../api/config/main.php',
'@common/../api/config/main-local.php',
],
],
],
# ...
]
```

Now you can generate completion for the desired group:
Now you can generate autocompletion for the desired group:
```bash
php yii ide-components --config=api
```
Expand Down
145 changes: 91 additions & 54 deletions source/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
use Yii;
use \Exception;
use yii\base\InvalidCallException;
use yii\base\InvalidConfigException;
use yii\helpers\FileHelper;

/**
* Class Controller
*
* @package iiifx\Yii2\Autocomplete
*/
class Controller extends \yii\console\Controller
{
/**
* @var string
*/
public $component = 'autocomplete';

/**
* @var Detector
*/
protected $detector;

/**
* @var string
*/
Expand All @@ -46,8 +57,9 @@ public function optionAliases ()
*/
public function init ()
{
echo "Yii2 IDE Autocomplete Helper\n";
echo "Vitaliy IIIFX Khomenko (c) 2016\n";
echo
'Yii2 IDE Autocomplete Helper' . PHP_EOL .
'Vitaliy IIIFX Khomenko, 2016' . PHP_EOL;
}

/**
Expand All @@ -56,63 +68,88 @@ public function init ()
public function actionIndex ()
{
try {
if ( isset( Yii::$app->{$this->component} ) && Yii::$app->{$this->component} instanceof Component ) {
$component = Yii::$app->{$this->component};
# Определяем тип приложения и конфигурационные файлы
$detector = new Detector( [
'app' => Yii::$app,
] );
if ( $component->config === null ) {
# В компоненте не указаны файлы конфигурации
if ( $detector->detect() === false ) {
throw new InvalidCallException( 'Unable to determine application type' );
}
$configList = $detector->getConfig();
$component = $this->getComponent();
$configList = $this->getConfig( $component );
$config = new Config( [
'files' => $configList,
] );
$builder = new Builder( [
'components' => $config->getComponents(),
'template' => require __DIR__ . '/template.php',
] );
if ( $component->result === null ) {
$component->result = ( $this->getDetector()->detect() === 'basic' ) ?
'@app/_ide_components.php' :
'@console/../_ide_components.php';
}
$result = Yii::getAlias( $component->result );
$result = FileHelper::normalizePath( $result );
if ( $builder->build( $result ) ) {
echo PHP_EOL . 'Success: ' . $result;
} else {
echo PHP_EOL . 'Fail!';
}
} catch ( Exception $exception ) {
echo
PHP_EOL . $exception->getMessage() .
PHP_EOL . 'Please read the package documentation: https://github.com/iiifx-production/yii2-autocomplete-helper' .
PHP_EOL;
}
}

/**
* @return Component
*
* @throws InvalidConfigException
*/
protected function getComponent ()
{
if ( isset( Yii::$app->{$this->component} ) && Yii::$app->{$this->component} instanceof Component ) {
return Yii::$app->{$this->component};
}
throw new InvalidConfigException( "Component '{$this->component}' not found in Yii::\$app" );
}

/**
* @return Detector
*/
protected function getDetector ()
{
if ( $this->detector === null ) {
$this->detector = new Detector( [
'app' => Yii::$app,
] );
}
return $this->detector;
}

/**
* @param Component $component
*
* @return array
*/
protected function getConfig ( Component $component )
{
if ( $component->config === null ) {
if ( $this->getDetector()->detect() === false ) {
throw new InvalidCallException( 'Unable to determine application type' );
}
$configList = $this->getDetector()->getConfig();
} else {
if ( $this->config === null ) {
if ( isset( $component->config[ 0 ] ) ) {
$configList = $component->config;
} else {
# Файлы конфигурации указаны
if ( $this->config === null ) {
if ( isset( $component->config[ 0 ] ) ) {
$configList = $component->config;
} else {
throw new InvalidCallException( "Default config list not found in component config data" );
}
} else {
if ( isset( $component->config[ $this->config ] ) ) {
$configList = $component->config[ $this->config ];
} else {
throw new InvalidCallException( "Scope '{$this->config}' not found in component config data" );
}
}
throw new InvalidCallException( 'Default config list not found in component config data' );
}
# Читаем конфигурационные файлы
$config = new Config( [
'files' => $configList,
] );
$builder = new Builder( [
'components' => $config->getComponents(),
'template' => require __DIR__ . '/template.php',
] );
if ( $component->result === null ) {
$component->result = ( $detector->detect() === 'basic' ) ?
'@app/_ide_components.php' :
'@console/../_ide_components.php';
}
$result = Yii::getAlias( $component->result );
$result = FileHelper::normalizePath( $result );
if ( $builder->build( $result ) ) {
echo "\nSuccess: {$result}";
} else {
if ( isset( $component->config[ $this->config ] ) ) {
$configList = $component->config[ $this->config ];
} else {
echo "\nFail!";
throw new InvalidCallException( "Scope '{$this->config}' not found in component config data" );
}
} else {
echo "\nComponent '{$name}' not found in Yii::\$app";
echo "\nPlease read package documentation: ";
echo "https://github.com/iiifx-production/yii2-autocomplete-helper\n";
}
} catch ( Exception $exception ) {
echo "\n" . $exception->getMessage();
echo "\nPlease read package documentation: ";
echo "https://github.com/iiifx-production/yii2-autocomplete-helper\n";
}
return $configList;
}
}

0 comments on commit fe2a9c5

Please sign in to comment.