Skip to content

Commit

Permalink
Removed singleton configuration (#92)
Browse files Browse the repository at this point in the history
* Added namespace for tests.

* Added missing @php to reference same php bin.

* Specify returned type.

* Added FileParser class to parse config file.

* Added bootstrap.php file to bootstrap test.

* Added property-access component.

* Added NonSingletonConfiguration to replace existing configuration based on singleton pattern.

* Added Task Collection.

* Make config directory path OS-independent.

* Rename Crunz\Console\CommandKernel to Crunz\Application.

* Put envvar CRUNZ_BASE_DIR in test env.

* Use non static configuration.

* Added var-dumper.

* Use task collection in ScheduleRun command,

* Cache composer's files in CI.

* Disable xdebug in CI.

* Use NonSingleton configuration in schedule:run command.

* Removed finder dependency from schedule:run command.

* Do not use singleton configuration in TaskGenerator command.

* Use functions from global namespace.

* Added some tests to Invoker.

* Register Invoker service.

* Use injected EventRunner instead of created in-place.

* Remove configurable trait.

* Make logger factory non static and remove trait with configuration.

* Removed singleton configuration.

* Rename configuration class.

* Rename and CS fix.

* Removed Singleton class.

* Make setting answer portable.

* Replace symfony polyfills for PHP below 5.6.
  • Loading branch information
PabloKowalczyk authored May 20, 2018
1 parent a399306 commit 8ac4170
Show file tree
Hide file tree
Showing 34 changed files with 967 additions and 482 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ env:
global:
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-progress --no-suggest --prefer-dist"

cache:
directories:
- $HOME/.composer/cache

before_install:
- phpenv config-rm xdebug.ini || return 0;
- composer self-update

install:
Expand Down
14 changes: 14 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';

$testCrunzRoot = \implode(
DIRECTORY_SEPARATOR,
[
__DIR__,
'tests'
]
);

\define('CRUNZ_ROOT', $testCrunzRoot);
\putenv('CRUNZ_BASE_DIR=' . $testCrunzRoot);
22 changes: 17 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@
"symfony/dependency-injection": "^2.7 || ^3.3 || ^4.0",
"symfony/finder": "^2.7 || ^3.3 || ^4.0",
"symfony/process": "^2.7.11 || ^3.3 || ^4.0",
"symfony/yaml": "^2.7 || ^3.3 || ^4.0"
"symfony/yaml": "^2.7 || ^3.3 || ^4.0",
"symfony/property-access": "^2.7 || ^3.3 || ^4.0"
},
"require-dev": {
"ext-mbstring": "*",
"friendsofphp/php-cs-fixer": "2.2.19",
"phpdocumentor/reflection-docblock": "^2.0.1",
"phpunit/phpunit": "5.7.27",
"sebastian/comparator": "1.2.4",
"symfony/debug": "^2.7 || ^3.3 || ^4.0",
"symfony/phpunit-bridge": "^2.8 || ^3.3 || ^4.0"
"symfony/debug": "^3.3 || ^4.0",
"symfony/phpunit-bridge": "^2.8 || ^3.3 || ^4.0",
"symfony/var-dumper": "^3.4"
},
"replace": {
"symfony/polyfill-php56": "*",
"symfony/polyfill-php55": "*",
"symfony/polyfill-php54": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -57,6 +64,11 @@
"src/Helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Crunz\\Tests\\": "tests/"
}
},
"bin": [
"crunz"
],
Expand All @@ -69,7 +81,7 @@
}
},
"scripts": {
"crunz:cs-fix": "vendor/bin/php-cs-fixer fix --diff -v --ansi",
"crunz:analyze": "vendor/bin/php-cs-fixer fix --diff --dry-run -v"
"crunz:cs-fix": "@php vendor/bin/php-cs-fixer fix --diff -v --ansi",
"crunz:analyze": "@php vendor/bin/php-cs-fixer fix --diff --dry-run -v"
}
}
94 changes: 92 additions & 2 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
id="Crunz\Console\Command\ScheduleRunCommand"
public="true"
>
<argument type="service" id="Symfony\Component\Finder\Finder"/>
<argument type="service" id="Crunz\Task\Collection"/>
<argument type="service" id="Crunz\Configuration\Configuration"/>
<argument type="service" id="Crunz\EventRunner"/>
</service>

<service
Expand All @@ -32,20 +34,108 @@
id="Crunz\Console\Command\ScheduleListCommand"
public="true"
>
<argument type="service" id="Symfony\Component\Finder\Finder"/>
<argument type="service" id="Crunz\Configuration\Configuration"/>
<argument type="service" id="Crunz\Task\Collection"/>
</service>

<service
class="Crunz\Console\Command\TaskGeneratorCommand"
id="Crunz\Console\Command\TaskGeneratorCommand"
public="true"
>
<argument type="service" id="Crunz\Configuration\Configuration"/>
</service>

<service
class="Symfony\Component\Finder\Finder"
id="Symfony\Component\Finder\Finder"
public="false"
/>

<service
class="Crunz\Configuration\Definition"
id="Crunz\Configuration\Definition"
public="false"
/>

<service
class="Symfony\Component\Yaml\Yaml"
id="Symfony\Component\Yaml\Yaml"
public="false"
/>

<service
class="Symfony\Component\Config\Definition\Processor"
id="Symfony\Component\Config\Definition\Processor"
public="false"
/>

<service
class="Crunz\Task\Collection"
id="Crunz\Task\Collection"
public="false"
>
<argument type="service" id="Crunz\Configuration\Configuration"/>
<argument type="service" id="Symfony\Component\Finder\Finder"/>
</service>

<service
class="Crunz\Configuration\FileParser"
id="Crunz\Configuration\FileParser"
public="false"
>
<argument type="service" id="Symfony\Component\Yaml\Yaml" />
</service>

<service
class="Symfony\Component\PropertyAccess\PropertyAccessor"
id="Symfony\Component\PropertyAccess\PropertyAccessorInterface"
>
<argument type="string">false</argument>
<argument type="string">true</argument>
</service>

<service
class="Crunz\Configuration\Configuration"
id="Crunz\Configuration\Configuration"
public="false"
>
<argument type="service" id="Crunz\Configuration\Definition"/>
<argument type="service" id="Symfony\Component\Config\Definition\Processor"/>
<argument type="service" id="Crunz\Configuration\FileParser"/>
<argument type="service" id="Symfony\Component\PropertyAccess\PropertyAccessorInterface"/>
</service>

<service
class="Crunz\Invoker"
id="Crunz\Invoker"
public="false"
/>

<service
class="Crunz\Mailer"
id="Crunz\Mailer"
public="false"
>
<argument type="service" id="Crunz\Configuration\Configuration"/>
</service>

<service
class="Crunz\Logger\LoggerFactory"
id="Crunz\Logger\LoggerFactory"
>
<argument type="service" id="Crunz\Configuration\Configuration"/>
</service>

<service
class="Crunz\EventRunner"
id="Crunz\EventRunner"
public="false"
>
<argument type="service" id="Crunz\Invoker"/>
<argument type="service" id="Crunz\Configuration\Configuration"/>
<argument type="service" id="Crunz\Mailer"/>
<argument type="service" id="Crunz\Logger\LoggerFactory"/>
</service>
</services>
</container>
2 changes: 1 addition & 1 deletion crunz
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ define('CRUNZ_ROOT', __DIR__);
// Setting the base directory as an environment variable
setbase(getroot($hasBinAutoloader ? $autoloadBin : $autoloadSrc));

$application = new Crunz\Console\CommandKernel('Crunz Command Line Interface', 'v1.6.1');
$application = new Crunz\Application('Crunz Command Line Interface', 'v1.6.1');
$application->run();
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="bootstrap.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
Expand Down
15 changes: 12 additions & 3 deletions src/Console/CommandKernel.php → src/Application.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Crunz\Console;
namespace Crunz;

use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator;
Expand All @@ -10,7 +10,7 @@
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

class CommandKernel extends SymfonyApplication
class Application extends SymfonyApplication
{
/**
* List of commands to register.
Expand Down Expand Up @@ -104,7 +104,16 @@ private function buildContainer()
{
$containerBuilder = new ContainerBuilder();

$loader = new XmlFileLoader($containerBuilder, new FileLocator(CRUNZ_ROOT . '/config'));
$configDir = \implode(
DIRECTORY_SEPARATOR,
[
__DIR__,
'..',
'config',
]
);

$loader = new XmlFileLoader($containerBuilder, new FileLocator($configDir));
$loader->load('services.xml');

return $containerBuilder;
Expand Down
18 changes: 18 additions & 0 deletions src/Configuration/ConfigFileNotExistsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Crunz\Configuration;

use Crunz\Exception\CrunzException;

class ConfigFileNotExistsExtension extends CrunzException
{
/**
* @param string $filePath
*
* @return ConfigFileNotExistsExtension
*/
public static function fromFilePath($filePath)
{
return new self("Configuration file '{$filePath}' not exists.");
}
}
18 changes: 18 additions & 0 deletions src/Configuration/ConfigFileNotReadableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Crunz\Configuration;

use Crunz\Exception\CrunzException;

class ConfigFileNotReadableException extends CrunzException
{
/**
* @param string $filePath
*
* @return ConfigFileNotReadableException
*/
public static function fromFilePath($filePath)
{
return new self("Config file '{$filePath}' is not readable.");
}
}
39 changes: 0 additions & 39 deletions src/Configuration/Configurable.php

This file was deleted.

Loading

0 comments on commit 8ac4170

Please sign in to comment.