Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class AbstactEntityFactory
- {
- /**
- * @param mixed[] $state
- */
- abstract public function createEntity(array $state): EntityInterface;
- /**
- * @param mixed[] $state
- */
- abstract public function createEntityCollection(array $states): EntityCollectionInterface;
- }
- class FooEntityFactory extends AbstactEntityFactory
- {
- /**
- * {@inheritdoc}
- */
- public function createEntity(array $state): EntityInterface
- {
- return Foo::fromState($state);
- }
- /**
- * {@inheritdoc}
- */
- public function createEntityCollection(array $states): EntityCollectionInterface
- {
- return new FooCollection(array_map('Foo::fromState', $states));
- }
- }
- class BarEntityFactory extends AbstactEntityFactory
- {
- /**
- * {@inheritdoc}
- */
- public function createEntity(array $state): EntityInterface
- {
- return Bar::fromState($state);
- }
- /**
- * {@inheritdoc}
- */
- public function createEntityCollection(array $states): EntityCollectionInterface
- {
- return new BarCollection(array_map('Bar::fromState', $states));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement