diff options
-rw-r--r-- | composer.json | 4 | ||||
-rw-r--r-- | composer.lock | 718 | ||||
-rw-r--r-- | src/Config/Config.php | 18 | ||||
-rw-r--r-- | src/Core/Main.php | 25 | ||||
-rw-r--r-- | src/Game.php | 19 | ||||
-rw-r--r-- | src/Message/Base.php | 83 | ||||
-rw-r--r-- | src/Message/Handler.php | 72 | ||||
-rw-r--r-- | src/Message/Overview.php | 50 |
8 files changed, 958 insertions, 31 deletions
diff --git a/composer.json b/composer.json index 08fb2ef..8354340 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,10 @@ { "require": { - "mustache/mustache": "^2.11" + "mustache/mustache": "^2.11", + "cboden/ratchet": "^0.3.1" }, "autoload": { "psr-4": {"App\\": "src/"} + } }
\ No newline at end of file diff --git a/composer.lock b/composer.lock index 367dd36..baec83b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,305 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "58a49ddda9ef333b2bf511ceffee55ff", + "content-hash": "b7e6341c0b95532a46f5ef9adf54dbe0", "packages": [ { + "name": "cboden/ratchet", + "version": "v0.3.6", + "source": { + "type": "git", + "url": "https://github.com/ratchetphp/Ratchet.git", + "reference": "84df35d2a6576985b9e81b564d3c25809f8d647e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ratchetphp/Ratchet/zipball/84df35d2a6576985b9e81b564d3c25809f8d647e", + "reference": "84df35d2a6576985b9e81b564d3c25809f8d647e", + "shasum": "" + }, + "require": { + "guzzle/http": "^3.6", + "php": ">=5.3.9", + "react/socket": "^0.3 || ^0.4", + "symfony/http-foundation": "^2.2|^3.0", + "symfony/routing": "^2.2|^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Ratchet\\": "src/Ratchet" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "role": "Developer" + } + ], + "description": "PHP WebSocket library", + "homepage": "http://socketo.me", + "keywords": [ + "Ratchet", + "WebSockets", + "server", + "sockets" + ], + "time": "2017-01-06T14:36:36+00:00" + }, + { + "name": "evenement/evenement", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/igorw/evenement.git", + "reference": "f6e843799fd4f4184d54d8fc7b5b3551c9fa803e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/igorw/evenement/zipball/f6e843799fd4f4184d54d8fc7b5b3551c9fa803e", + "reference": "f6e843799fd4f4184d54d8fc7b5b3551c9fa803e", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-0": { + "Evenement": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch", + "homepage": "http://wiedler.ch/igor/" + } + ], + "description": "Événement is a very simple event dispatching library for PHP", + "keywords": [ + "event-dispatcher", + "event-emitter" + ], + "time": "2012-11-02T14:49:47+00:00" + }, + { + "name": "guzzle/common", + "version": "v3.9.2", + "target-dir": "Guzzle/Common", + "source": { + "type": "git", + "url": "https://github.com/Guzzle3/common.git", + "reference": "2e36af7cf2ce3ea1f2d7c2831843b883a8e7b7dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Guzzle3/common/zipball/2e36af7cf2ce3ea1f2d7c2831843b883a8e7b7dc", + "reference": "2e36af7cf2ce3ea1f2d7c2831843b883a8e7b7dc", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "symfony/event-dispatcher": ">=2.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Common": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Common libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "collection", + "common", + "event", + "exception" + ], + "abandoned": "guzzle/guzzle", + "time": "2014-08-11T04:32:36+00:00" + }, + { + "name": "guzzle/http", + "version": "v3.9.2", + "target-dir": "Guzzle/Http", + "source": { + "type": "git", + "url": "https://github.com/Guzzle3/http.git", + "reference": "1e8dd1e2ba9dc42332396f39fbfab950b2301dc5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Guzzle3/http/zipball/1e8dd1e2ba9dc42332396f39fbfab950b2301dc5", + "reference": "1e8dd1e2ba9dc42332396f39fbfab950b2301dc5", + "shasum": "" + }, + "require": { + "guzzle/common": "self.version", + "guzzle/parser": "self.version", + "guzzle/stream": "self.version", + "php": ">=5.3.2" + }, + "suggest": { + "ext-curl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Http": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "HTTP libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "client", + "curl", + "http", + "http client" + ], + "abandoned": "guzzle/guzzle", + "time": "2014-08-11T04:32:36+00:00" + }, + { + "name": "guzzle/parser", + "version": "v3.9.2", + "target-dir": "Guzzle/Parser", + "source": { + "type": "git", + "url": "https://github.com/Guzzle3/parser.git", + "reference": "6874d171318a8e93eb6d224cf85e4678490b625c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Guzzle3/parser/zipball/6874d171318a8e93eb6d224cf85e4678490b625c", + "reference": "6874d171318a8e93eb6d224cf85e4678490b625c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Parser": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Interchangeable parsers used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "URI Template", + "cookie", + "http", + "message", + "url" + ], + "abandoned": "guzzle/guzzle", + "time": "2014-02-05T18:29:46+00:00" + }, + { + "name": "guzzle/stream", + "version": "v3.9.2", + "target-dir": "Guzzle/Stream", + "source": { + "type": "git", + "url": "https://github.com/Guzzle3/stream.git", + "reference": "60c7fed02e98d2c518dae8f97874c8f4622100f0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Guzzle3/stream/zipball/60c7fed02e98d2c518dae8f97874c8f4622100f0", + "reference": "60c7fed02e98d2c518dae8f97874c8f4622100f0", + "shasum": "" + }, + "require": { + "guzzle/common": "self.version", + "php": ">=5.3.2" + }, + "suggest": { + "guzzle/http": "To convert Guzzle request objects to PHP streams" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Stream": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle stream wrapper component", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "component", + "stream" + ], + "abandoned": "guzzle/guzzle", + "time": "2014-05-01T21:36:02+00:00" + }, + { "name": "mustache/mustache", "version": "v2.11.1", "source": { @@ -51,6 +347,426 @@ "templating" ], "time": "2016-07-31T06:18:27+00:00" + }, + { + "name": "react/event-loop", + "version": "v0.4.2", + "source": { + "type": "git", + "url": "https://github.com/reactphp/event-loop.git", + "reference": "164799f73175e1c80bba92a220ea35df6ca371dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/event-loop/zipball/164799f73175e1c80bba92a220ea35df6ca371dd", + "reference": "164799f73175e1c80bba92a220ea35df6ca371dd", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "suggest": { + "ext-event": "~1.0", + "ext-libev": "*", + "ext-libevent": ">=0.1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5-dev" + } + }, + "autoload": { + "psr-4": { + "React\\EventLoop\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Event loop abstraction layer that libraries can use for evented I/O.", + "keywords": [ + "asynchronous", + "event-loop" + ], + "time": "2016-03-08T02:09:32+00:00" + }, + { + "name": "react/promise", + "version": "v2.5.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "2760f3898b7e931aa71153852dcd48a75c9b95db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/2760f3898b7e931aa71153852dcd48a75c9b95db", + "reference": "2760f3898b7e931aa71153852dcd48a75c9b95db", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2016-12-22T14:09:01+00:00" + }, + { + "name": "react/socket", + "version": "v0.4.6", + "source": { + "type": "git", + "url": "https://github.com/reactphp/socket.git", + "reference": "cf074e53c974df52388ebd09710a9018894745d2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/socket/zipball/cf074e53c974df52388ebd09710a9018894745d2", + "reference": "cf074e53c974df52388ebd09710a9018894745d2", + "shasum": "" + }, + "require": { + "evenement/evenement": "~2.0|~1.0", + "php": ">=5.3.0", + "react/event-loop": "0.4.*|0.3.*", + "react/promise": "^2.0 || ^1.1", + "react/stream": "^0.4.5" + }, + "require-dev": { + "clue/block-react": "^1.1", + "phpunit/phpunit": "~4.8", + "react/socket-client": "^0.5.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Socket\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Async, streaming plaintext TCP/IP and secure TLS socket server for React PHP", + "keywords": [ + "Socket" + ], + "time": "2017-01-26T09:23:38+00:00" + }, + { + "name": "react/stream", + "version": "v0.4.6", + "source": { + "type": "git", + "url": "https://github.com/reactphp/stream.git", + "reference": "44dc7f51ea48624110136b535b9ba44fd7d0c1ee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/stream/zipball/44dc7f51ea48624110136b535b9ba44fd7d0c1ee", + "reference": "44dc7f51ea48624110136b535b9ba44fd7d0c1ee", + "shasum": "" + }, + "require": { + "evenement/evenement": "^2.0|^1.0", + "php": ">=5.3.8" + }, + "require-dev": { + "clue/stream-filter": "~1.2", + "react/event-loop": "^0.4|^0.3", + "react/promise": "^2.0|^1.0" + }, + "suggest": { + "react/event-loop": "^0.4", + "react/promise": "^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Stream\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Basic readable and writable stream interfaces that support piping.", + "keywords": [ + "pipe", + "stream" + ], + "time": "2017-01-25T14:44:14+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v3.2.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d", + "reference": "b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/dependency-injection": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/stopwatch": "~2.8|~3.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2017-02-21T09:12:04+00:00" + }, + { + "name": "symfony/http-foundation", + "version": "v3.2.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-foundation.git", + "reference": "c57009887010eb4e58bfca2970314a5b820b24b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/c57009887010eb4e58bfca2970314a5b820b24b9", + "reference": "c57009887010eb4e58bfca2970314a5b820b24b9", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.1" + }, + "require-dev": { + "symfony/expression-language": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpFoundation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony HttpFoundation Component", + "homepage": "https://symfony.com", + "time": "2017-03-04T12:23:14+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4", + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2016-11-14T01:06:16+00:00" + }, + { + "name": "symfony/routing", + "version": "v3.2.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/routing.git", + "reference": "d6605f9a5767bc5bc4895e1c762ba93964608aee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/routing/zipball/d6605f9a5767bc5bc4895e1c762ba93964608aee", + "reference": "d6605f9a5767bc5bc4895e1c762ba93964608aee", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "conflict": { + "symfony/config": "<2.8" + }, + "require-dev": { + "doctrine/annotations": "~1.0", + "doctrine/common": "~2.2", + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/http-foundation": "~2.8|~3.0", + "symfony/yaml": "~2.8|~3.0" + }, + "suggest": { + "doctrine/annotations": "For using the annotation loader", + "symfony/config": "For using the all-in-one router or any loader", + "symfony/dependency-injection": "For loading routes from a service", + "symfony/expression-language": "For using expression matching", + "symfony/http-foundation": "For using a Symfony Request object", + "symfony/yaml": "For using the YAML loader" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Routing\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Routing Component", + "homepage": "https://symfony.com", + "keywords": [ + "router", + "routing", + "uri", + "url" + ], + "time": "2017-03-02T15:58:09+00:00" } ], "packages-dev": [], diff --git a/src/Config/Config.php b/src/Config/Config.php index 10236f0..710c9e0 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -2,10 +2,26 @@ namespace App\Config; +/** + * Config class to handle loading and returning config stuff + * + * @author Phil Burton <phil@pgburton.com> + */ class Config { + /** + * Cached config + * + * @var mixed[] + */ protected static $config; + /** + * Return the cofnig + * + * @author Phil Burton <phil@pgburton.com> + * @return mixed[] + */ public static function getconfig() { if (!static::$config) { @@ -14,4 +30,4 @@ class Config return static::$config; } -}
\ No newline at end of file +} diff --git a/src/Core/Main.php b/src/Core/Main.php index 594b15c..7aa643e 100644 --- a/src/Core/Main.php +++ b/src/Core/Main.php @@ -5,11 +5,15 @@ namespace App\Core; use App\Game; /** -* Core Main class, deals with all set-up -*/ + * Not really sure if we need this + */ class Main { - + /** + * Construct + * + * @author Phil Burton <phil@pgburton.com> + */ public function __construct() { $this->init(); @@ -17,13 +21,24 @@ class Main $this->run(); } + /** + * Initalise + * + * @author Phil Burton <phil@pgburton.com> + * @return bool + */ protected function init() { return true; } + /** + * Run the Game + * + * @author Phil Burton <phil@pgburton.com> + */ protected function run() { - $game = new Game(); + $game = new Game(); } -}
\ No newline at end of file +} diff --git a/src/Game.php b/src/Game.php index c2141ce..1bedba2 100644 --- a/src/Game.php +++ b/src/Game.php @@ -6,16 +6,26 @@ use App\Message\Handler; /** * A Game class that handles game execution + * + * @author Phil Burton <phil@pgburton.com> */ class Game { - protected $messages; - + /** + * Constuct a new Game + * + * @author Phil Burton <phil@pgburton.com> + */ public function __construct() { $this->init(); } + /** + * Initalise the Game + * + * @author Phil Burton <phil@pgburton.com> + */ protected function init() { // Do any pre set-up @@ -23,6 +33,10 @@ class Game $this->sendOpeningMessage(); } + /** + * Send opening message + * @author Phil Burton <phil@pgburton.com> + */ public function sendOpeningMessage() { $message = $this->handler->renderOpeningMessage(); @@ -33,5 +47,4 @@ class Game var_dump($message, $important, $message2); } - } diff --git a/src/Message/Base.php b/src/Message/Base.php index 4565de9..2b7b0e4 100644 --- a/src/Message/Base.php +++ b/src/Message/Base.php @@ -8,15 +8,51 @@ use App\Message\Handler; /** * Base class for a message +* +* @author Phil Burton <phil@pgburton.com> */ class Base { + /** + * Message name to load + * + * @var string + */ protected $message_name; + + /** + * Cache of the loaded config array + * + * @var string + */ protected $config; + + /** + * The raw message string loaded from config + * + * @var string + */ protected $message; + + /** + * The list of vars we need to inject + * + * @var array + */ protected $injects = []; + + /** + * The array of important vars + * + * @var string + */ protected $important; + /** + * Load the message from the config + * + * @author Phil Burton <phil@pgburton.com> + */ protected function loadMessage() { if (!array_key_exists($this->message_name, $this->config)) { @@ -26,6 +62,9 @@ class Base $this->message = $this->config[$this->message_name]; } + /** + * Load the config + */ protected function loadConfig() { $config =Config::getConfig(); @@ -37,39 +76,65 @@ class Base $this->config = $config; } + /** + * Construct, load config and message + * + * @author Phil Burton <phil@pgburton.com> + */ public function __construct() { $this->loadConfig(); - + $this->loadMessage(); } + /** + * Render the message, injecting any values into the message using mustache + * + * @author Phil Burton <phil@pgburton.com> + */ public function renderMessage() { $m = new Mustache_Engine; return $m->render($this->message, $this->getInjectValues()); } + + /** + * Return the injected values + * + * @author Phil Burton <phil@pgburton.com> + */ public function getInjectValues() { $out = []; - foreach ($this->injects as $inject) { - $out[$inject] = $this->$inject; - } + foreach ($this->injects as $inject) { + $out[$inject] = $this->$inject; + } return $out; } + /** + * Get the important injected values + * + * @author Phil Burton <phil@pgburton.com> + */ public function getImportantValues() { - $out = []; - foreach ($this->important as $important) { - $out[$important] = $this->$important; - } + $out = []; + foreach ($this->important as $important) { + $out[$important] = $this->$important; + } return $out; } + /** + * Set-up this message's inject values based on an input array + * + * @author Phil Burton <phil@pgburton.com> + */ public function setFromArray(array $array) { foreach ($array as $key => $value) { @@ -78,4 +143,4 @@ class Base } } } -}
\ No newline at end of file +} diff --git a/src/Message/Handler.php b/src/Message/Handler.php index 89752c5..825ceda 100644 --- a/src/Message/Handler.php +++ b/src/Message/Handler.php @@ -6,25 +6,52 @@ use App\Message\Overview; /** * Handles messages and context +* +* @author Phil Burton <phil@pgburton.com> */ class Handler { + /** + * The important set of injects for this handler + * + * @var string[] + */ protected $important = []; + /** + * The important set of values of injects for this handler + * + * @var mixed[] + */ protected $importantValues = []; + /** + * Construct our handler + * + * @author Phil Burton <phil@pgburton.com> + * @param string[] $important + */ public function __construct($important) { $this->setupImportant($important); } /** - * Set's up important attributes on this class + * Set the important list + * + * @author Phil Burton <phil@pgburton.com> + * @param string[] $important */ public function setupImportant($important = []) { $this->important = $important; } + /** + * Set important values + * + * @author Phil Burton <phil@pgburton.com> + * @param mixed[] $array + */ protected function setImportantValues($array) { foreach ($array as $name => $value) { @@ -32,6 +59,13 @@ class Handler } } + /** + * Add an important value to our array + * + * @author Phil Burton <phil@pgburton.com> + * @param string $name + * @param mixed[] $value + */ protected function addImportantValue($name, $value) { if (in_array($name, $this->important)) { @@ -41,15 +75,31 @@ class Handler return $name; } + /** + * Get a single important value + * + * @author Phil Burton <phil@pgburton.com> + * @param string $name + * @return mixed + */ public function returnImportant($name) { if (!array_key_exists($name, $this->importantValues)) { throw new \Exception('The var ' . $name . ' is not set in this context'); } - + return $this->importantValues[$name]; } + /** + * Magic __call override to be able to get improtant values using getMyImportant() + * which then runs $this->returnImportant('myImportant') + * + * @author Phil Burton <phil@pgburton.com> + * @param string $name + * @param mixed[] $arguments + * @return string + */ public function __call($name, $arguments) { if (strpos($name, 'get') === 0) { @@ -57,16 +107,22 @@ class Handler } } + /** + * Render the opening message + * + * @author Phil Burton <phil@pgburton.com> + * @return string + */ public function renderOpeningMessage() { - $overview = new Overview(); + $overview = new Overview(); - $overview->setFromArray($this->importantValues); + $overview->setFromArray($this->importantValues); - $message = $overview->renderMessage(); + $message = $overview->renderMessage(); - $this->setImportantValues($overview->getImportantValues()); + $this->setImportantValues($overview->getImportantValues()); - return $message; + return $message; } -}
\ No newline at end of file +} diff --git a/src/Message/Overview.php b/src/Message/Overview.php index c328acc..0494c16 100644 --- a/src/Message/Overview.php +++ b/src/Message/Overview.php @@ -4,22 +4,66 @@ namespace App\Message; use App\Message\Base; +/** + * Overview message + * + * @author Phil Burton <phil@pgburton.com> + */ class Overview extends Base { - protected $message_name = 'opening'; + /** + * Message name to load + * + * @var string + */ + protected $message_name; + + /** + * The list of vars we need to inject + * + * @var array + */ protected $injects = ['inject', 'second']; + + /** + * The array of important vars + * + * @var string + */ protected $important = ['inject']; + + /** + * Inject + * @var string + */ public $inject; + + /** + * Second inject + * + * @var string + */ public $second = "second"; + /** + * Construct to set any inject vars from functions if required + * + * @author Phil Burton <phil@pgburton.com> + */ public function __construct() { $this->inject = $this->getInject(); parent::__construct(); } + /** + * Get our inject value + * + * @author Phil Burton <phil@pgburton.com> + * @return string + */ public function getInject() { - return time(); + return (string) time(); } -}
\ No newline at end of file +} |