Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- /**
- * Interface IPayload
- */
- interface IPayload {
- public function toArray(): array;
- }
- /**
- * Interface ChildPayloadInterface
- */
- interface ChildPayloadInterface {
- public function setVar(string $var);
- }
- /**
- * Interface GenericPayload
- */
- interface GenericPayload extends IPayload, ChildPayloadInterface {
- }
- /**
- * Interface IPayloadFactory
- */
- interface IPayloadFactory {
- public function create(): IPayload;
- }
- /**
- * Interface IChildPayloadFactory
- */
- interface IChildPayloadFactory {
- public function create(): GenericPayload;
- }
- /**
- * Class Payload
- */
- class Payload implements IPayload {
- public function toArray(): array {
- return ['hello' => 'world'];
- }
- }
- /**
- * Class ChildPayload
- */
- class ChildPayload extends Payload implements GenericPayload {
- public function setVar(string $var) {
- $this->var = $var;
- }
- }
- /**
- * Class ChildPayloadFactory
- */
- class ChildPayloadFactory implements IChildPayloadFactory {
- public function create(): GenericPayload {
- return new ChildPayload();
- }
- }
- $factory = new ChildPayloadFactory();
- var_dump($factory->create());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement