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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ VIM Plugin
This application standalone, but it does include a plugin for VIM, see the
[plugin README](https://github.com/dantleech/phpactor/tree/master/plugin/README.md).

Configuration
-------------

Configuration files are merged from the XDG open base dir standard, and from
the current working directory, for example:

```
/etc/xdg/phpactor/phpactor.yml
/home/daniel/.config/phpactor/phpactor.yml
<currnent directory>/.phpactor.yml
```

All configuration options are defined in the
`Phpactor\Container\CoreExtension` class.

Commands
--------

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"dantleech/source-code-filesystem": "dev-master",
"dantleech/type-inference": "dev-master",
"symfony/filesystem": "^3.3",
"webmozart/glob": "^4.1"
"webmozart/glob": "^4.1",
"dnoegel/php-xdg-base-dir": "^0.1.0",
"symfony/yaml": "^3.3"
},
"require-dev": {
"phpunit/phpunit": "^5.2",
Expand Down
1 change: 1 addition & 0 deletions lib/Application/FileInfo/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function infoForOffset(string $sourcePath, int $offset): array
$return = [
'type' => (string) $type,
'path' => null,

];

if (InferredType::unknown() == $type) {
Expand Down
29 changes: 28 additions & 1 deletion lib/UserInterface/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Symfony\Component\Console\Application as SymfonyApplication;
use PhpBench\DependencyInjection\Container;
use Phpactor\Container\CoreExtension;
use XdgBaseDir\Xdg;
use Webmozart\PathUtil\Path;
use Symfony\Component\Yaml\Yaml;

class Application extends SymfonyApplication
{
Expand All @@ -15,9 +18,10 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')

public function initialize()
{
$config = $this->loadConfig();
$container = new Container([
CoreExtension::class,
], []);
], $this->loadConfig());
$container->init();
$this->addCommands([
$container->get('command.class_move'),
Expand All @@ -26,4 +30,27 @@ public function initialize()
$container->get('command.file_offset'),
]);
}

private function loadConfig(): array
{
$xdg = new Xdg();
$configDirs = $xdg->getConfigDirs();

$configPaths = array_map(function ($configPath) {
return Path::join($configPath, '/phpactor/phpactor.yml');
}, $configDirs);
$configPaths[] = Path::join(getcwd(), '.phpactor.yml');

$config = [];
foreach ($configPaths as $configPath) {
if (file_exists($configPath)) {
$config = array_merge(
$config,
Yaml::parse(file_get_contents($configPath))
);
}
}

return $config;
}
}
3 changes: 1 addition & 2 deletions lib/UserInterface/Console/Command/ClassSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ private function outputConsole(OutputInterface $output, array $results)
continue;
}

var_dump($result);die();;
$output->writeln(sprintf('<comment>%s</><info>:</>%s', $result['class'], $result['path']));
$output->writeln(sprintf('<comment>%s</><info>:</>%s', $result['class'], $result['file_path']));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function replacing(FilePath $path, FoundReferences $references, FullyQual

foreach ($references->references() as $reference) {
$this->output->writeln(sprintf(
' %s:%s %s <comment>=></> %s',
' %s:%s %s <comment>=></> %s',
$reference->position()->start(),
$reference->position()->end(),
(string) $reference->name(),
Expand Down
33 changes: 33 additions & 0 deletions tests/UserInterface/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Phpactor\Tests\UserInterface;

use Phpactor\Tests\UserInterface\SystemTestCase;
use Phpactor\UserInterface\Console\Application;

class ApplicationTest extends SystemTestCase
{
public function setUp()
{
$this->initWorkspace();
}

/**
* @testdox It should throw an exception when an invalid configuration key is present.
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unknown configuration
*/
public function testConfig()
{
file_put_contents(
$this->workspaceDir() . '/.phpactor.yml',
<<<'EOT'
foobar_invalid: something
EOT
);

chdir($this->workspaceDir());
$application = new Application();
$application->initialize();
}
}