Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog

Features:

- [code-builder] Generates typed property for PHP 7.4 - @elythyr
- [phpactor|code-builder] Allow to override the templates by PHP version - @elythyr
- [worse-reflection] Support for PHP 7.4 property types - @dantleech / @elythyr
- [code-transform|rpc] Import missing classes - @dantleech
- [context-menu] Invoke menu for the nearest actionable node (i.e. you can
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Reference

### Core

#### core.php_version

*Default*: Your current version of PHP (e.g. `7.3.0`)

You can override it if your local PHP installation does not match the one used
by your project.

#### composer.autoloader_path

*Default*: `vendor/autoload.php`
Expand Down Expand Up @@ -127,6 +134,8 @@ or any of the XDG directories (e.g. `$HOME/.config/phpactor/templates`).
*Default*: `<xdg paths>/templates` and local project `.phpactor/templates`

Directories where class templates can be located.
The order matter since the system will look for a template in each directory
and stop on the first match.

### Navigator Extension

Expand Down
28 changes: 18 additions & 10 deletions lib/Extension/CodeTransformExtra/CodeTransformExtraExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Phpactor\CodeBuilder\Adapter\Twig\TwigExtension;
use Phpactor\CodeBuilder\Adapter\Twig\TwigRenderer;
use Phpactor\CodeBuilder\Adapter\WorseReflection\WorseBuilderFactory;
use Phpactor\CodeBuilder\Domain\TemplatePathResolver\PhpVersionPathResolver;
use Phpactor\CodeBuilder\Util\TextFormat;
use Phpactor\CodeTransform\Adapter\Native\GenerateNew\ClassGenerator;
use Phpactor\CodeTransform\Adapter\TolerantParser\ClassToFile\Transformer\ClassNameFixerTransformer;
Expand All @@ -28,6 +29,7 @@
use Phpactor\Container\Extension;
use Phpactor\Extension\CodeTransformExtra\Rpc\ImportMissingClassesHandler;
use Phpactor\Extension\CodeTransform\CodeTransformExtension;
use Phpactor\Extension\Core\CoreExtension;
use Phpactor\Extension\Logger\LoggingExtension;
use Phpactor\Extension\Rpc\RpcExtension;
use Phpactor\Extension\Console\ConsoleExtension;
Expand Down Expand Up @@ -61,6 +63,7 @@ class CodeTransformExtraExtension implements Extension
const INDENTATION = 'code_transform.indentation';
const GENERATE_ACCESSOR_PREFIX = 'code_transform.refactor.generate_accessor.prefix';
const GENERATE_ACCESSOR_UPPER_CASE_FIRST = 'code_transform.refactor.generate_accessor.upper_case_first';
const APP_TEMPLATE_PATH = '%application_root%/vendor/phpactor/code-builder/templates';

/**
* {@inheritDoc}
Expand All @@ -69,7 +72,7 @@ public function configure(Resolver $schema)
{
$schema->setDefaults([
self::CLASS_NEW_VARIANTS => [],
self::TEMPLATE_PATHS => [
self::TEMPLATE_PATHS => [ // Ordered by priority
'%project_config%/templates',
'%config%/templates',
],
Expand Down Expand Up @@ -173,17 +176,22 @@ private function registerRenderer(ContainerBuilder $container)
{
$container->register('code_transform.twig_loader', function (Container $container) {
$resolver = $container->get(FilePathResolverExtension::SERVICE_FILE_PATH_RESOLVER);
$loaders = [];
$loaders[] = new FilesystemLoader($resolver->resolve('%application_root%/vendor/phpactor/code-builder/templates'));

foreach ($container->getParameter(self::TEMPLATE_PATHS) as $templatePath) {
$templatePath = $resolver->resolve($templatePath);
if (file_exists($templatePath)) {
$loaders[] = new FilesystemLoader($templatePath);
}
$loader = new ChainLoader();
$templatePaths = $container->getParameter(self::TEMPLATE_PATHS);
$templatePaths[] = self::APP_TEMPLATE_PATH;

$resolvedTemplatePaths = array_map(function (string $path) use ($resolver) {
return $resolver->resolve($path);
}, $templatePaths);

$phpVersion = $container->getParameter(CoreExtension::PARAM_PHP_VERSION);
$paths = (new PhpVersionPathResolver($phpVersion))->resolve($resolvedTemplatePaths);

foreach ($paths as $path) {
$loader->addLoader(new FilesystemLoader($path));
}

return new ChainLoader($loaders);
return $loader;
});

$container->register('code_transform.renderer', function (Container $container) {
Expand Down
17 changes: 10 additions & 7 deletions lib/Extension/Core/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ class CoreExtension implements Extension
{
const APP_NAME = 'phpactor';
const APP_VERSION = '0.2.0';
const DUMPER = 'console_dumper_default';
const XDEBUG_DISABLE = 'xdebug_disable';
const COMMAND = 'command';

const PARAM_DUMPER = 'console_dumper_default';
const PARAM_XDEBUG_DISABLE = 'xdebug_disable';
const PARAM_COMMAND = 'command';
const PARAM_PHP_VERSION = 'core.php_version';

public function configure(Resolver $schema)
{
$schema->setDefaults([
self::DUMPER => 'indented',
self::XDEBUG_DISABLE => true,
self::COMMAND => null,
self::PARAM_DUMPER => 'indented',
self::PARAM_XDEBUG_DISABLE => true,
self::PARAM_COMMAND => null,
self::PARAM_PHP_VERSION => phpversion(),
]);
}

Expand Down Expand Up @@ -82,7 +85,7 @@ private function registerConsole(ContainerBuilder $container)
$dumpers[$attrs['name']] = $container->get($dumperId);
}

return new DumperRegistry($dumpers, $container->getParameter(self::DUMPER));
return new DumperRegistry($dumpers, $container->getParameter(self::PARAM_DUMPER));
});

$container->register('console.dumper.indented', function (Container $container) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Phpactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public static function boot(InputInterface $input, string $vendorDir): PhpactorC
->loader();

$config = $loader->load();
$config[CoreExtension::COMMAND] = $input->getFirstArgument();
$config[CoreExtension::PARAM_COMMAND] = $input->getFirstArgument();
$config[FilePathResolverExtension::PARAM_APPLICATION_ROOT] = self::resolveApplicationRoot();
$config = self::configureExtensionManager($config, $vendorDir);

if ($input->hasParameterOption([ '--working-dir', '-d' ])) {
$config[FilePathResolverExtension::PARAM_PROJECT_ROOT] = $cwd = $input->getParameterOption([ '--working-dir', '-d' ]);
}

if (!isset($config[CoreExtension::XDEBUG_DISABLE]) || $config[CoreExtension::XDEBUG_DISABLE]) {
if (!isset($config[CoreExtension::PARAM_XDEBUG_DISABLE]) || $config[CoreExtension::PARAM_XDEBUG_DISABLE]) {
$xdebug = new XdebugHandler('PHPACTOR', '--ansi');
$xdebug->check();
unset($xdebug);
Expand Down