Skip to content

Commit

Permalink
Feature/cli runner (#393)
Browse files Browse the repository at this point in the history
* Start work on Cli runner

* More work on CLI runner

* More work

* Changes to support better testing, custom CLI runner

* Final CLI runner implementation

* Move fixture to test directory

* Refactor decorator collection into v3

* Remove the tools composer.lock files

* Fix install, fix removal of fixture_src

* Try fixing autoload paths

* Adjust gitignore to include moved test files
  • Loading branch information
cspray committed Jun 16, 2024
1 parent 7624e82 commit a5c5242
Show file tree
Hide file tree
Showing 466 changed files with 4,414 additions and 8,195 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ phpunit.xml export-ignore
psalm.xml export-ignore
CODE_OF_CONDUCT.md export-ignore
CONTRIBUTING.md export-ignore
fixture_src export-ignore
test export-ignore
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
..
.phpunit.cache
architectural-decisions.xml.bak
composer.lock
/**/composer.lock
build/
vendor/
/vendor
/tools/**/vendor
21 changes: 9 additions & 12 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,28 @@ _default:
just --list --unsorted

# Install all dependencies necesesary to run Annotated Container tools
install: _install_ac
install: _install_labrador_cs _install_phpunit _install_psalm _install_ac

_install_ac:
composer install

_install_labrador_cs:
cd tools/labrador-cs
composer install
cd tools/labrador-cs && composer install

_install_phpunit:
cd tools/phpunit
composer install
cd tools/phpunit && composer install

_install_psalm:
cd tools/psalm
composer install
cd tools/psalm && composer install

# Run unit tests
test:
@XDEBUG_MODE=coverage ./tools/phpunit/vendor/bin/phpunit
test *FLAGS:
@XDEBUG_MODE=coverage ./tools/phpunit/vendor/bin/phpunit {{FLAGS}}

# Run static analysis checks on src and test
static-analysis:
static-analysis *FLAGS:
@./tools/psalm/vendor/bin/psalm --version
@./tools/psalm/vendor/bin/psalm
@./tools/psalm/vendor/bin/psalm {{FLAGS}}

# Set the baseline of known issues to be used during static analysis
static-analysis-set-baseline:
Expand All @@ -50,7 +47,7 @@ code-lint:
code-lint-fix:
@./tools/labrador-cs/vendor/bin/phpcbf -p --standard=./tools/labrador-cs/vendor/cspray/labrador-coding-standard/ruleset.xml --exclude=Generic.Files.LineLength src test

# Run all CI checks
# Run all CI checks. ALL checks will run, regardless of failures
ci-check:
-@just test
-@just static-analysis
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $emitter = new Emitter();

// Include other active profiles in this list
// If the only active profile is default you can call this method without any arguments
$container = Bootstrap::fromMinimalSetup($emitter)->bootstrapContainer(
$container = Bootstrap::from($emitter)->bootstrapContainer(
Profiles::fromList(['default'])
);

Expand Down
34 changes: 24 additions & 10 deletions annotated-container-definition.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<xs:complexType name="serviceDefinitionType">
<xs:all>
<xs:element name="type" type="xs:token" />
<xs:element name="type" type="fullyQualifiedClassNameType" />
<xs:element name="name" type="xs:token" />
<xs:element name="profiles" type="profilesType" />
<xs:element name="concreteOrAbstract" type="concreteOrAbstractType" />
Expand All @@ -59,8 +59,8 @@

<xs:complexType name="aliasDefinitionType">
<xs:all>
<xs:element name="abstractService" type="xs:token" />
<xs:element name="concreteService" type="xs:token" />
<xs:element name="abstractService" type="fullyQualifiedClassNameType" />
<xs:element name="concreteService" type="fullyQualifiedClassNameType" />
</xs:all>
</xs:complexType>

Expand All @@ -72,8 +72,8 @@

<xs:complexType name="servicePrepareDefinitionType">
<xs:all>
<xs:element name="type" type="xs:token" />
<xs:element name="method" type="xs:token" />
<xs:element name="type" type="fullyQualifiedClassNameType" />
<xs:element name="method" type="classMethodType" />
<xs:element name="attribute" type="xs:string" />
</xs:all>
</xs:complexType>
Expand All @@ -86,9 +86,9 @@

<xs:complexType name="serviceDelegateDefinitionType">
<xs:all>
<xs:element name="service" type="xs:token" />
<xs:element name="delegateType" type="xs:token" />
<xs:element name="delegateMethod" type="xs:token" />
<xs:element name="service" type="fullyQualifiedClassNameType" />
<xs:element name="delegateType" type="fullyQualifiedClassNameType" />
<xs:element name="delegateMethod" type="classMethodType" />
<xs:element name="attribute" type="xs:string" />
</xs:all>
</xs:complexType>
Expand All @@ -101,8 +101,8 @@

<xs:complexType name="injectDefinitionType">
<xs:all>
<xs:element name="class" type="xs:token" />
<xs:element name="method" type="xs:token" />
<xs:element name="class" type="fullyQualifiedClassNameType" />
<xs:element name="method" type="classMethodType" />
<xs:element name="parameter" type="xs:token" />
<xs:element name="valueType" type="xs:token" />
<xs:element name="value" type="xs:string" />
Expand All @@ -124,4 +124,18 @@
<xs:enumeration value="Abstract" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="fullyQualifiedClassNameType">
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:pattern value="[a-zA-Z_&#x80;-&#xff;][a-zA-Z0-9_&#x80;-&#xff;]*(\\[a-zA-Z_&#x80;-&#xff;][a-zA-Z0-9_&#x80;-&#xff;]*)*" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="classMethodType">
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:pattern value="[a-zA-Z_&#x80;-&#xff;][a-zA-Z0-9_&#x80;-&#xff;]*" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
25 changes: 9 additions & 16 deletions architectural-decisions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ We explicitly do no allow setting a profile on a Configuration. The Configuratio
to define values. Any value that should only be injected when certain profiles are active should have that reflected
in the #[Inject] Attribute. This way just 1 Configuration instance is required and any profile-specific values are
defined on the value itself.]]></contents>
<codeAnnotations>
<codeAnnotation>
<class>Cspray\AnnotatedContainer\Attribute\Configuration</class>
</codeAnnotation>
</codeAnnotations>
<meta>
<author>
<name>Charles Sprayberry</name>
Expand Down Expand Up @@ -58,13 +53,19 @@ you know precisely what code is determining the services for your application.]]
<codeAnnotation>
<classMethod>
<class>Cspray\AnnotatedContainer\Bootstrap\XmlBootstrappingConfiguration</class>
<method>getContainerDefinitionProvider</method>
<method>containerDefinitionProvider</method>
</classMethod>
</codeAnnotation>
<codeAnnotation>
<classMethod>
<class>Cspray\AnnotatedContainer\Bootstrap\CacheAwareBootstrappingConfiguration</class>
<method>containerDefinitionProvider</method>
</classMethod>
</codeAnnotation>
<codeAnnotation>
<classMethod>
<class>Cspray\AnnotatedContainer\Bootstrap\BootstrappingConfiguration</class>
<method>getContainerDefinitionProvider</method>
<method>containerDefinitionProvider</method>
</classMethod>
</codeAnnotation>
<codeAnnotation>
Expand All @@ -76,7 +77,7 @@ you know precisely what code is determining the services for your application.]]
<codeAnnotation>
<classMethod>
<class>Cspray\AnnotatedContainer\StaticAnalysis\ContainerDefinitionAnalysisOptions</class>
<method>getDefinitionProvider</method>
<method>definitionProvider</method>
</classMethod>
</codeAnnotation>
</codeAnnotations>
Expand Down Expand Up @@ -215,14 +216,6 @@ was made obsolete with constructor property promotion.
We could simply add these pieces of the ConfigurationAttribute but at that point we're effectively duplicating the
ServiceAttribute. Instead of that, we should discourage the use of the ConfigurationAttribute. If you require similar
functionality, you should implement your own custom ServiceAttribute.]]></contents>
<codeAnnotations>
<codeAnnotation>
<class>Cspray\AnnotatedContainer\Attribute\ConfigurationAttribute</class>
</codeAnnotation>
<codeAnnotation>
<class>Cspray\AnnotatedContainer\Attribute\Configuration</class>
</codeAnnotation>
</codeAnnotations>
<meta>
<author>
<name>Charles Sprayberry</name>
Expand Down
35 changes: 3 additions & 32 deletions bin/annotated-container
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

use Cspray\AnnotatedContainer\Bootstrap\RootDirectoryBootstrappingDirectoryResolver;
use Cspray\AnnotatedContainer\Bootstrap\ComposerJsonScanningThirdPartyInitializerProvider;
use Cspray\AnnotatedContainer\Cli\Command\ValidateCommand;
use Cspray\AnnotatedContainer\Cli\Command\BuildCommand;
use Cspray\AnnotatedContainer\Cli\Command\CacheClearCommand;
use Cspray\AnnotatedContainer\Cli\Command\HelpCommand;
use Cspray\AnnotatedContainer\Cli\Command\InitCommand;
use Cspray\AnnotatedContainer\Cli\CommandExecutor;
use Cspray\AnnotatedContainer\Cli\InputParser;
use Cspray\AnnotatedContainer\Cli\TerminalOutput;
use Cspray\AnnotatedContainer\Cli\AnnotatedContainerCliRunner;

$dir = dirname(__DIR__);
if (!file_exists($dir . '/vendor/autoload.php')) {
$dir = dirname(__DIR__, 4);
}

require_once $dir . '/vendor/autoload.php';

$directoryResolver = new RootDirectoryBootstrappingDirectoryResolver($dir);

$commandExecutor = new CommandExecutor();

$commandExecutor->defaultCommand(new HelpCommand($commandExecutor));
$commandExecutor->addCommand(new InitCommand($directoryResolver, new ComposerJsonScanningThirdPartyInitializerProvider($directoryResolver)));
$commandExecutor->addCommand(new BuildCommand($directoryResolver));
$commandExecutor->addCommand(new CacheClearCommand($directoryResolver));
$commandExecutor->addCommand(new ValidateCommand($directoryResolver));

$input = (new InputParser())->parse($argv);
$terminalOutput = new TerminalOutput();

$exitCode = $commandExecutor->execute($input, $terminalOutput);
exit($exitCode);
include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';

AnnotatedContainerCliRunner::setup(null)->run($argv);
29 changes: 14 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
"php": "^8.1",
"ext-dom": "*",
"ext-libxml": "*",
"composer-runtime-api": "^2",
"cspray/annotated-container-adr": "^3",
"cspray/annotated-container-attribute": "^1.3",
"composer-runtime-api": "^2.2",
"cspray/annotated-container-adr": "^3.2",
"cspray/annotated-container-attribute": "^2.0.0.alpha.5",
"cspray/annotated-target": "^v1.1",
"cspray/precision-stopwatch": "^0.2.0",
"cspray/typiphy": "^0.3",
"nikic/php-parser": "^5",
"nikic/php-parser": "^4.19",
"psr/container": "^2.0"
},
"require-dev": {
Expand All @@ -44,17 +44,15 @@
},
"autoload-dev": {
"psr-4": {
"Cspray\\AnnotatedContainer\\": "test",
"Cspray\\AnnotatedContainerFixture\\": "fixture_src"
"Cspray\\AnnotatedContainer\\": "test"
},
"files": [
"fixture_src/VendorScanningInitializers/vendor/cspray/package/other_src/DependencyDefinitionProvider.php",
"fixture_src/VendorScanningInitializers/vendor/cspray/package/src/FirstInitializer.php",
"fixture_src/VendorScanningInitializers/vendor/cspray/package/src/SecondInitializer.php",
"fixture_src/VendorScanningInitializers/vendor/cspray/package/src/SomeService.php",
"fixture_src/VendorScanningInitializers/vendor/cspray/package/other_src/ThirdInitializer.php",
"fixture_src/VendorScanningInitializers/vendor/cspray/package/src/ThirdPartyDependency.php",
"fixture_src/VendorScanningInitializers/src/ActualService.php"
"./test/Fixture/VendorScanningInitializers/vendor/cspray/package/src/SomeService.php",
"./test/Fixture/VendorScanningInitializers/src/ActualService.php",
"./test/Fixture/VendorScanningInitializers/vendor/cspray/package/src/FirstInitializer.php",
"./test/Fixture/VendorScanningInitializers/vendor/cspray/package/src/SecondInitializer.php",
"./test/Fixture/VendorScanningInitializers/vendor/cspray/package/src/ThirdPartyDependency.php",
"./test/Fixture/VendorScanningInitializers/vendor/cspray/package/other_src/ThirdInitializer.php"
]
},
"suggest": {
Expand All @@ -64,8 +62,9 @@
},
"extra": {
"$architecturalDecision": {
"initializers": [
"Cspray\\AnnotatedContainer\\ArchitecturalDecisions\\Initializer"
"additionalScanPaths": [
"vendor/cspray/annotated-container-adr/src",
"vendor/cspray/annotated-container-attribute/src"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/01-add-third-party-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use Psr\Log\LoggerInterface;
use Cspray\AnnotatedContainer\Bootstrap\Bootstrap;
use Cspray\AnnotatedContainer\Event\Emitter;

$container = Bootstrap::fromMinimalSetup(new Emitter())->bootstrapContainer();
$container = Bootstrap::from(new Emitter())->bootstrapContainer();
```

Now, your PSR Logger will be created through a factory. Any services can inject a `LoggerInterface` directly in the constructor, preferred, or implement the `LoggerAwareInterface` to have it injected automatically after construction.
12 changes: 6 additions & 6 deletions docs/how-to/02-bootstrap-your-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ $emitter = new Emitter();

// Add Listeners to respond to events emitted by Annotated Container

$container = Bootstrap::fromMinimalSetup($emitter)->bootstrapContainer();
$container = Bootstrap::from($emitter)->bootstrapContainer();
```

It is important in this code that you add whatever Listeners might be appropriate to the `$emitter` using `Emitter::addListener`. This includes any Listeners that you might be using from third-party libraries. There is currently no plans to allow Listeners to be defined through configuration and MUST be added as part of your bootstrapping. The Emitter is one of the few pieces of Bootstrapping that is ALWAYS required. It cannot be stressed enough how important setting up your Listeners are in this section of your code.
Expand All @@ -151,7 +151,7 @@ use Cspray\AnnotatedContainer\Bootstrap\Bootstrap;
use Cspray\AnnotatedContainer\Event\Emitter;
use Cspray\AnnotatedContainer\Profiles;

$container = Bootstrap::fromMinimalSetup(new Emitter())
$container = Bootstrap::from(new Emitter())
->bootstrapContainer(Profiles::fromList(['default', 'prod']));
```

Expand All @@ -167,7 +167,7 @@ namespace Acme\Demo;
use Cspray\AnnotatedContainer\Bootstrap\Bootstrap;
use Cspray\AnnotatedContainer\Bootstrap\XmlBootstrappingConfigurationProvider;use Cspray\AnnotatedContainer\Event\Emitter;use Cspray\AnnotatedContainer\Profiles;

$container = Bootstrap::fromMinimalSetup(new Emitter)
$container = Bootstrap::from(new Emitter)
->bootstrapContainer(bootstrappingConfigurationProvider: new XmlBootstrappingConfigurationProvider('my-container.xml'));
```

Expand All @@ -188,7 +188,7 @@ use Cspray\AnnotatedContainer\Event\Emitter;
// This method is an implementation provided by the reader
$definitionProviderFactory = MyDefinitionProviderFactory::create();

$container = Bootstrap::fromMinimalSetup(
$container = Bootstrap::from(
new Emitter(),
definitionProviderFactory: $definitionProviderFactory
))->bootstrapContainer();
Expand All @@ -209,7 +209,7 @@ use Cspray\AnnotatedContainer\Event\Emitter;
// This method is an implementation provided by the reader
$parameterStoreFactory = MyParameterStoreFactory::create();

$container = Bootstrap::fromMinimalSetup(
$container = Bootstrap::from(
new Emitter(),
parameterStoreFactory: $parameterStoreFactory
))->bootstrapContainer();
Expand Down Expand Up @@ -259,7 +259,7 @@ use Cspray\AnnotatedContainer\Bootstrap\DefaultParameterStoreFactory;
use Cspray\AnnotatedContainer\Bootstrap\XmlBootstrappingConfigurationProvider;use Cspray\AnnotatedContainer\ContainerFactory\PhpDiContainerFactory;
use Cspray\AnnotatedContainer\Definition\Cache\FileBackedContainerDefinitionCache;use Cspray\AnnotatedContainer\Definition\Serializer\XmlContainerDefinitionSerializer;use Cspray\AnnotatedContainer\Event\Emitter;

$container = Bootstrap::fromMinimalSetup(new Emitter())
$container = Bootstrap::from(new Emitter())
->bootstrapContainer(
bootstrappingConfigurationProvider: new CacheAwareBootstrappingConfigurationProvider(
new XmlBootstrappingConfigurationProvider(),
Expand Down
7 changes: 0 additions & 7 deletions fixture_src/BeanLikeConfigConcrete/FooService.php

This file was deleted.

7 changes: 0 additions & 7 deletions fixture_src/BeanLikeConfigInterface/FooInterface.php

This file was deleted.

8 changes: 0 additions & 8 deletions fixture_src/CustomServiceAttribute/MyRepo.php

This file was deleted.

Loading

0 comments on commit a5c5242

Please sign in to comment.