Skip to content

Commit

Permalink
Merge pull request #14 from zfegg/develop
Browse files Browse the repository at this point in the history
Add `SerializationPreparerStackFactory`
  • Loading branch information
Moln authored Feb 27, 2023
2 parents ba166d5 + cc3fcd2 commit f44fd43
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Container/SerializationPreparerStackFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types = 1);

namespace Zfegg\PsrMvc\Container;

use Psr\Container\ContainerInterface;
use Zfegg\PsrMvc\Preparer\CommonPreparer;
use Zfegg\PsrMvc\Preparer\DefaultPreparer;
use Zfegg\PsrMvc\Preparer\PreparerStack;
use Zfegg\PsrMvc\Preparer\ResultPreparableInterface;
use Zfegg\PsrMvc\Preparer\SerializationPreparer;

class SerializationPreparerStackFactory
{

public function __invoke(ContainerInterface $container): ResultPreparableInterface
{
$preparer = new PreparerStack();
$preparer->push($container->get(DefaultPreparer::class));
$preparer->push($container->get(SerializationPreparer::class));
$preparer->push($container->get(CommonPreparer::class));

return $preparer;
}
}
23 changes: 23 additions & 0 deletions test/Container/SerializationPreparerStackFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types = 1);

namespace ZfeggTest\PsrMvc\Container;

use Zfegg\PsrMvc\Container\SerializationPreparerStackFactory;
use Zfegg\PsrMvc\Preparer\PreparerStack;

use Zfegg\PsrMvc\Preparer\SerializationPreparer;
use ZfeggTest\PsrMvc\AbstractTestCase;

class SerializationPreparerStackFactoryTest extends AbstractTestCase
{

public function testInvoke(): void
{
$this->container->setFactory(PreparerStack::class, SerializationPreparerStackFactory::class);
$preparer = $this->container->get(PreparerStack::class);

$this->assertInstanceOf(SerializationPreparer::class, $preparer[1]);
}
}

0 comments on commit f44fd43

Please sign in to comment.