-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from yohang/feature/symfony-bundle
feature: Adds Symfony Bundle to 2.0
- Loading branch information
Showing
23 changed files
with
294 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
vendor | ||
build | ||
bin | ||
composer.phar | ||
tests/Extension/Symfony/Fixtures/app/var/ | ||
vendor/ | ||
.phpunit.result.cache | ||
composer.lock | ||
cache.properties | ||
coverage.clover | ||
docs/_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
tests/Extension/Symfony/Fixtures/app/var/ | ||
vendor/ | ||
.phpunit.result.cache | ||
vendor | ||
build | ||
bin | ||
composer.phar | ||
composer.lock | ||
cache.properties | ||
coverage.clover | ||
docs/_build | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Extension/Symfony/Bundle/DependencyInjection/FiniteExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Finite\Extension\Symfony\Bundle\DependencyInjection; | ||
|
||
use Finite\Extension\Twig\FiniteExtension as TwigExtension; | ||
use Finite\StateMachine; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
final class FiniteExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$container->addDefinitions( | ||
[ | ||
StateMachine::class => (new Definition(StateMachine::class)) | ||
->setArgument('$dispatcher', new Reference('event_dispatcher')) | ||
->setPublic(true), | ||
TwigExtension::class => new Definition(TwigExtension::class), | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Finite\Extension\Symfony\Bundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
final class FiniteBundle extends Bundle | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/Extension/Symfony/Bundle/DependencyInjection/FiniteExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Finite\Tests\Extension\Symfony\Bundle\DependencyInjection; | ||
|
||
use Finite\Extension\Symfony\Bundle\DependencyInjection\FiniteExtension; | ||
use Finite\Extension\Twig\FiniteExtension as TwigExtension; | ||
use Finite\StateMachine; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class FiniteExtensionTest extends TestCase | ||
{ | ||
public function test_it_loads_services(): void | ||
{ | ||
$container = $this->getMockBuilder(ContainerBuilder::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$container->expects($this->once())->method('addDefinitions')->with( | ||
$this->logicalAnd( | ||
$this->countOf(2), | ||
$this->arrayHasKey(StateMachine::class), | ||
$this->arrayHasKey(TwigExtension::class), | ||
), | ||
); | ||
|
||
$extension = new FiniteExtension; | ||
$extension->load([], $container); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Finite\Tests\Extension\Symfony\Fixtures\Model; | ||
|
||
use Finite\Tests\Extension\Symfony\Fixtures\State\DocumentState; | ||
|
||
class Document | ||
{ | ||
public DocumentState $state = DocumentState::DRAFT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Finite\Tests\Extension\Symfony\Fixtures\State; | ||
|
||
use Finite\State; | ||
use Finite\Transition\Transition; | ||
|
||
enum DocumentState: string implements State | ||
{ | ||
case DRAFT = 'draft'; | ||
case PUBLISHED = 'published'; | ||
case REPORTED = 'reported'; | ||
case DISABLED = 'disabled'; | ||
|
||
public static function getTransitions(): array | ||
{ | ||
return [ | ||
new Transition('publish', [self::DRAFT], self::PUBLISHED), | ||
new Transition('clear', [self::REPORTED, self::DISABLED], self::PUBLISHED), | ||
new Transition('report', [self::PUBLISHED], self::REPORTED), | ||
new Transition('disable', [self::REPORTED, self::PUBLISHED], self::DISABLED), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class AppKernel extends Kernel | ||
{ | ||
use MicroKernelTrait; | ||
|
||
public function registerBundles(): iterable | ||
{ | ||
return [ | ||
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new Finite\Extension\Symfony\Bundle\FiniteBundle(), | ||
]; | ||
} | ||
|
||
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void | ||
{ | ||
$c->setParameter('kernel.debug', true); | ||
$c->prependExtensionConfig('framework', ['test' => true, 'profiler' => true]); | ||
} | ||
|
||
public function getProjectDir(): string | ||
{ | ||
return __DIR__; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
$loader = require __DIR__ . '/../../../../../vendor/autoload.php'; | ||
require __DIR__.'/AppKernel.php'; | ||
|
||
return $loader; |
Oops, something went wrong.