Skip to content

Commit

Permalink
Merge pull request #50 from Trejjam/master
Browse files Browse the repository at this point in the history
Create DI::timestampStorage after call ContainerBuilder::getByType
  • Loading branch information
stekycz authored Nov 12, 2016
2 parents 1d3e6e5 + d41c2bd commit 8708c28
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ php:
- 5.6
- 7.0
- hhvm
- hhvm-nightly

env:
- PHP_BIN=php
- PHP_BIN=php-cgi

matrix:
allow_failures:
- php: 7.0
- php: hhvm
- php: hhvm-nightly

exclude:
- php: hhvm
env: PHP_BIN=php-cgi

- php: hhvm-nightly
env: PHP_BIN=php-cgi
before_install:
- if [[ "$TRAVIS_PHP_VERSION" == "hhvm" ]]; then cat tests/php.ini-unix >> /etc/hhvm/php.ini; fi
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then phpenv config-add tests/php.ini-unix; fi

install:
- if [[ "$TRAVIS_PHP_VERSION" == "5.3.3" ]]; then composer config -g disable-tls true; composer config -g secure-http false; fi
- composer self-update
- composer install --prefer-source --no-interaction --optimize-autoloader

Expand Down
22 changes: 17 additions & 5 deletions Cronner/DI/CronnerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Nette\Configurator;
use Nette\DI\Compiler;
use Nette\DI\CompilerExtension;
use Nette\DI\ContainerBuilder;
use Nette\DI\Statement;
use Nette\PhpGenerator\ClassType;
use Nette\Utils\Json;
Expand Down Expand Up @@ -34,7 +35,17 @@ class CronnerExtension extends CompilerExtension
'bar' => '%debugMode%'
);


/**
* @param ContainerBuilder $containerBuilder
*
* @return \Nette\DI\ServiceDefinition
*/
protected function createTimestampStorage(ContainerBuilder $containerBuilder)
{
return $containerBuilder->addDefinition($this->prefix('timestampStorage'))
->setAutowired(FALSE)
->setInject(FALSE);
}

public function loadConfiguration()
{
Expand All @@ -45,11 +56,11 @@ public function loadConfiguration()
Validators::assert($config['maxExecutionTime'], 'integer|null', 'Script max execution time');
Validators::assert($config['criticalSectionTempDir'], 'string', 'Critical section files directory path');

$storage = $container->addDefinition($this->prefix('timestampStorage'))
->setAutowired(FALSE)
->setInject(FALSE);

if ($config['timestampStorage'] === NULL) {
$storageServiceName = $container->getByType('stekycz\Cronner\ITimestampStorage');

$storage = $this->createTimestampStorage($container);
if ($storageServiceName) {
$storage->setFactory('@' . $storageServiceName);
} else {
Expand All @@ -58,6 +69,7 @@ public function loadConfiguration()
));
}
} else {
$storage = $this->createTimestampStorage($container);
if (is_string($config['timestampStorage']) && $container->getServiceName($config['timestampStorage'])) {
$storage->setFactory($config['timestampStorage']);
} else {
Expand Down Expand Up @@ -131,4 +143,4 @@ public static function register(Configurator $configurator)
};
}

}
}
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,5 @@
},
"autoload-dev": {
"classmap": ["tests/CronnerTests/objects"]
},
"config": {
"disable-tls": true
}
}
17 changes: 10 additions & 7 deletions tests/CronnerTests/DI/CronnerExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CronnerExtensionTest extends \TestCase
public function testDefaultConfiguration()
{
$compiler = $this->compiler;
$compiler->compile(array());
$compiler->compile();

$timestampStorage = $compiler->getContainerBuilder()->getDefinition('cronner.timestampStorage');
$criticalSection = $compiler->getContainerBuilder()->getDefinition('cronner.criticalSection');
Expand All @@ -65,13 +65,16 @@ class CronnerExtensionTest extends \TestCase
public function testCompleteConfiguration()
{
$compiler = $this->compiler;
$compiler->compile(array(
'cronner' => array(
'timestampStorage' => new Nette\DI\Statement('stekycz\Cronner\TimestampStorage\DummyStorage'),
'maxExecutionTime' => 120,
'criticalSectionTempDir' => '%tempDir%/cronner',
$compiler->addConfig(
array(
'cronner' => array(
'timestampStorage' => new Nette\DI\Statement('stekycz\Cronner\TimestampStorage\DummyStorage'),
'maxExecutionTime' => 120,
'criticalSectionTempDir' => '%tempDir%/cronner',
)
)
));
);
$compiler->compile();

$timestampStorage = $compiler->getContainerBuilder()->getDefinition('cronner.timestampStorage');
$criticalSection = $compiler->getContainerBuilder()->getDefinition('cronner.criticalSection');
Expand Down

0 comments on commit 8708c28

Please sign in to comment.