Skip to content

Commit

Permalink
Merge branch 'release/1.10.0' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Feb 28, 2022
2 parents 147b6ef + e269e0c commit 7674239
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 71 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @khalwat @bencroker
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## 1.10.0 - 2022.02.27
### Added
* Added compatibility with Craft CMS `^4.0.0` and Craft CMS `^3.0.0`
* Added `CODEOWNERS`

### Changed
* Code refactor/reformat

## 1.0.9 - 2021.12.23
### Changed
* Check to see if a file exists via `is_file()` before attempting to delete it with `unlink()`
Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/?branch=develop) [![Code Coverage](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/?branch=develop) [![Build Status](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/badges/build.png?b=develop)](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/build-status/develop) [![Code Intelligence Status](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/badges/code-intelligence.svg?b=develop)](https://scrutinizer-ci.com/code-intelligence)

# Autocomplete for Craft CMS 3.x
# Autocomplete for Craft CMS 3.x & 4.x

Provides Twig template IDE autocompletion for Craft CMS and plugin/module variables and element types.

Expand All @@ -13,7 +13,7 @@ Works with PhpStorm provided the [Symfony Support plugin](https://plugins.jetbra

## Requirements

This plugin requires Craft CMS 3.0.0 or later.
This package requires Craft CMS ^3.0.0 or Craft CMS ^4.0.0.

## Usage

Expand All @@ -24,7 +24,7 @@ composer require nystudio107/craft-autocomplete --dev
```

2. Ensure that the [Symfony Support plugin](https://plugins.jetbrains.com/plugin/7219-symfony-plugin) for PhpStorm is installed and enabled by checking the **Enabled for Project** checkbox in the Symfony plugin settings.

3. Ensure that `devMode` is enabled.

4. Visit the Craft site on which the package is installed to generate the autocomplete classes in `storage/runtime/compiled_classes/` or run the following console command.
Expand Down Expand Up @@ -61,6 +61,21 @@ php craft clear-caches/temp-files

## Extending

You can extend the values that a `Generator` class adds using the `EVENT_BEFORE_GENERATE` event.

```php
use nystudio107\autocomplete\events\DefineGeneratorValuesEvent;
use nystudio107\autocomplete\generators\AutocompleteTwigExtensionGenerator;
use yii\base\Event;

Event::on(AutocompleteTwigExtensionGenerator::class,
AutocompleteTwigExtensionGenerator::EVENT_BEFORE_GENERATE,
function(DefineGeneratorValuesEvent $event) {
$event->values['myVariable'] = 'value';
}
);
```

In addition to the provided autocomplete generator types, you can write your own by implementing the `GeneratorInterface` class or extending the abstract `Generator` class (recommended).

```php
Expand Down
77 changes: 39 additions & 38 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
{
"name": "nystudio107/craft-autocomplete",
"description": "Provides Twig template IDE autocomplete of Craft CMS & plugin variables",
"type": "yii2-extension",
"version": "1.0.9",
"keywords": [
"craft",
"cms",
"craftcms",
"twig",
"symfony",
"autocomplete",
"auto",
"complete"
],
"support": {
"docs": "https://github.com/nystudio107/craft-autocomplete/blob/master/README.md",
"issues": "https://github.com/nystudio107/craft-autocomplete/issues"
"name": "nystudio107/craft-autocomplete",
"description": "Provides Twig template IDE autocomplete of Craft CMS & plugin variables",
"type": "yii2-extension",
"version": "1.10.0",
"keywords": [
"craft",
"cms",
"craftcms",
"twig",
"symfony",
"autocomplete",
"auto",
"complete"
],
"support": {
"docs": "https://github.com/nystudio107/craft-autocomplete/blob/v1/README.md",
"issues": "https://github.com/nystudio107/craft-autocomplete/issues",
"source": "https://github.com/nystudio107/craft-autocomplete"
},
"license": "MIT",
"authors": [
{
"name": "nystudio107",
"homepage": "https://nystudio107.com"
},
"license": "MIT",
"authors": [
{
"name": "nystudio107",
"homepage": "https://nystudio107.com"
},
{
"name": "PutYourLightsOn",
"homepage": "https://putyourlightson.com"
}
],
"require": {
"craftcms/cms": "^3.0.0"
},
"autoload": {
"psr-4": {
"nystudio107\\autocomplete\\": "src/"
}
},
"extra": {
"bootstrap": "nystudio107\\autocomplete\\Autocomplete"
{
"name": "PutYourLightsOn",
"homepage": "https://putyourlightson.com"
}
],
"require": {
"craftcms/cms": "^3.0.0 || ^4.0.0-alpha"
},
"autoload": {
"psr-4": {
"nystudio107\\autocomplete\\": "src/"
}
},
"extra": {
"bootstrap": "nystudio107\\autocomplete\\Autocomplete"
}
}
32 changes: 15 additions & 17 deletions src/Autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@

namespace nystudio107\autocomplete;

use nystudio107\autocomplete\base\Generator;
use nystudio107\autocomplete\console\controllers\AutocompleteController;
use nystudio107\autocomplete\generators\AutocompleteTwigExtensionGenerator;
use nystudio107\autocomplete\generators\AutocompleteVariableGenerator;

use Craft;
use craft\console\Application as CraftConsoleApp;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Globals;
use craft\services\Plugins;
use craft\web\Application as CraftWebApp;

use nystudio107\autocomplete\base\Generator;
use nystudio107\autocomplete\console\controllers\AutocompleteController;
use nystudio107\autocomplete\generators\AutocompleteTwigExtensionGenerator;
use nystudio107\autocomplete\generators\AutocompleteVariableGenerator;
use yii\base\Application as YiiApp;
use yii\base\BootstrapInterface;
use yii\base\Event;
Expand Down Expand Up @@ -112,11 +110,11 @@ public function bootstrap($app)
*/
public function registerEventHandlers()
{
Event::on(Plugins::class,Plugins::EVENT_AFTER_INSTALL_PLUGIN, [$this, 'regenerateAutocompleteClasses']);
Event::on(Plugins::class,Plugins::EVENT_AFTER_UNINSTALL_PLUGIN, [$this, 'deleteAutocompleteClasses']);
Event::on(Globals::class,Globals::EVENT_AFTER_SAVE_GLOBAL_SET, [$this, 'deleteAutocompleteClasses']);
Event::on(Plugins::class,Plugins::EVENT_AFTER_LOAD_PLUGINS, [$this, 'generateAutocompleteClasses']);
Craft::info('Event Handlers installed',__METHOD__);
Event::on(Plugins::class, Plugins::EVENT_AFTER_INSTALL_PLUGIN, [$this, 'regenerateAutocompleteClasses']);
Event::on(Plugins::class, Plugins::EVENT_AFTER_UNINSTALL_PLUGIN, [$this, 'deleteAutocompleteClasses']);
Event::on(Globals::class, Globals::EVENT_AFTER_SAVE_GLOBAL_SET, [$this, 'deleteAutocompleteClasses']);
Event::on(Plugins::class, Plugins::EVENT_AFTER_LOAD_PLUGINS, [$this, 'generateAutocompleteClasses']);
Craft::info('Event Handlers installed', __METHOD__);
}

/**
Expand All @@ -125,11 +123,11 @@ public function registerEventHandlers()
public function generateAutocompleteClasses()
{
$autocompleteGenerators = $this->getAllAutocompleteGenerators();
foreach($autocompleteGenerators as $generatorClass) {
foreach ($autocompleteGenerators as $generatorClass) {
/* @var Generator $generatorClass */
$generatorClass::generate();
}
Craft::info('Autocomplete classes generated',__METHOD__);
Craft::info('Autocomplete classes generated', __METHOD__);
}

/**
Expand All @@ -138,11 +136,11 @@ public function generateAutocompleteClasses()
public function regenerateAutocompleteClasses()
{
$autocompleteGenerators = $this->getAllAutocompleteGenerators();
foreach($autocompleteGenerators as $generatorClass) {
foreach ($autocompleteGenerators as $generatorClass) {
/* @var Generator $generatorClass */
$generatorClass::regenerate();
}
Craft::info('Autocomplete classes regenerated',__METHOD__);
Craft::info('Autocomplete classes regenerated', __METHOD__);
}

/**
Expand All @@ -151,11 +149,11 @@ public function regenerateAutocompleteClasses()
public function deleteAutocompleteClasses()
{
$autocompleteGenerators = $this->getAllAutocompleteGenerators();
foreach($autocompleteGenerators as $generatorClass) {
foreach ($autocompleteGenerators as $generatorClass) {
/* @var Generator $generatorClass */
$generatorClass::delete();
}
Craft::info('Autocomplete classes deleted',__METHOD__);
Craft::info('Autocomplete classes deleted', __METHOD__);
}

// Protected Methods
Expand Down
3 changes: 1 addition & 2 deletions src/base/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

namespace nystudio107\autocomplete\base;

use nystudio107\autocomplete\Autocomplete;

use Craft;
use nystudio107\autocomplete\Autocomplete;

/**
* @author nystudio107
Expand Down
1 change: 0 additions & 1 deletion src/console/controllers/AutocompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace nystudio107\autocomplete\console\controllers;

use nystudio107\autocomplete\Autocomplete;

use yii\console\Controller;
use yii\console\ExitCode;
use yii\helpers\BaseConsole;
Expand Down
6 changes: 2 additions & 4 deletions src/generators/AutocompleteTwigExtensionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

namespace nystudio107\autocomplete\generators;

use nystudio107\autocomplete\base\Generator;
use nystudio107\autocomplete\events\DefineGeneratorValuesEvent;

use Craft;
use craft\base\Element;
use craft\web\twig\GlobalsExtension;

use nystudio107\autocomplete\base\Generator;
use nystudio107\autocomplete\events\DefineGeneratorValuesEvent;
use yii\base\Event;

/**
Expand Down
11 changes: 5 additions & 6 deletions src/generators/AutocompleteVariableGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

namespace nystudio107\autocomplete\generators;

use nystudio107\autocomplete\base\Generator;
use nystudio107\autocomplete\events\DefineGeneratorValuesEvent;

use Craft;
use craft\web\twig\variables\CraftVariable;

use nystudio107\autocomplete\base\Generator;
use nystudio107\autocomplete\events\DefineGeneratorValuesEvent;
use Throwable;
use yii\base\Event;

/**
Expand Down Expand Up @@ -82,7 +81,7 @@ private static function generateInternal()
foreach ($craftVariable->getComponents() as $key => $value) {
try {
$values[$key] = get_class($craftVariable->get($key));
} catch (\Throwable $e) {
} catch (Throwable $e) {
// That's okay
}
}
Expand All @@ -94,7 +93,7 @@ private static function generateInternal()
if (is_object($value) && !in_array($key, static::BEHAVIOR_PROPERTY_EXCLUDES, true)) {
$values[$key] = get_class($value);
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
// That's okay
}
}
Expand Down

0 comments on commit 7674239

Please sign in to comment.