| @@ 7-66 (lines=60) @@ | ||
| 4 | ||
| 5 | use \Exception; |
|
| 6 | ||
| 7 | class Memcached extends AbstractSystem |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @var \BFW\Memcache\MemcacheInterface|null $memcached The class used |
|
| 11 | * to connect to memcache(d) server. |
|
| 12 | * The class name should be declared into config file. |
|
| 13 | */ |
|
| 14 | protected $memcached; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * {@inheritdoc} |
|
| 18 | */ |
|
| 19 | public function __invoke() |
|
| 20 | { |
|
| 21 | return $this->memcached; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * Getter accessor to property memcached |
|
| 26 | * |
|
| 27 | * @return \BFW\Memcache\MemcacheInterface|null |
|
| 28 | */ |
|
| 29 | public function getMemcached() |
|
| 30 | { |
|
| 31 | return $this->memcached; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * {@inheritdoc} |
|
| 36 | * Load and initialize le memcached object |
|
| 37 | */ |
|
| 38 | public function init() |
|
| 39 | { |
|
| 40 | $this->loadMemcached(); |
|
| 41 | $this->initStatus = true; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Connect to memcache(d) server with the class declared in config file |
|
| 46 | * |
|
| 47 | * @return Object |
|
| 48 | * |
|
| 49 | * @throws Exception If memcached is enabled but no class is define. Or if |
|
| 50 | * The class declared into the config is not found. |
|
| 51 | */ |
|
| 52 | protected function loadMemcached() |
|
| 53 | { |
|
| 54 | $memcachedConfig = \BFW\Application::getInstance() |
|
| 55 | ->getConfig() |
|
| 56 | ->getValue('memcached', 'memcached.php') |
|
| 57 | ; |
|
| 58 | ||
| 59 | if ($memcachedConfig['enabled'] === false) { |
|
| 60 | return; |
|
| 61 | } |
|
| 62 | ||
| 63 | $this->memcached = new \BFW\Memcached; |
|
| 64 | $this->memcached->connectToServers(); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| @@ 5-46 (lines=42) @@ | ||
| 2 | ||
| 3 | namespace BFW\Core\AppSystems; |
|
| 4 | ||
| 5 | class Monolog extends AbstractSystem |
|
| 6 | { |
|
| 7 | /** |
|
| 8 | * @var \BFW\Monolog|null $monolog The monolog system for bfw channel |
|
| 9 | */ |
|
| 10 | protected $monolog; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * {@inheritdoc} |
|
| 14 | * |
|
| 15 | * @return \BFW\Monolog|null |
|
| 16 | */ |
|
| 17 | public function __invoke() |
|
| 18 | { |
|
| 19 | return $this->monolog; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @return \BFW\Monolog|null |
|
| 24 | */ |
|
| 25 | public function getMonolog() |
|
| 26 | { |
|
| 27 | return $this->monolog; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * {@inheritdoc} |
|
| 32 | * Initialize all monolog handlers declared for bfw channel |
|
| 33 | */ |
|
| 34 | public function init() |
|
| 35 | { |
|
| 36 | $config = \BFW\Application::getInstance()->getConfig(); |
|
| 37 | $this->monolog = new \BFW\Monolog('bfw', $config); |
|
| 38 | $this->monolog->addAllHandlers('handlers', 'monolog.php'); |
|
| 39 | ||
| 40 | $this->monolog->getLogger()->debug( |
|
| 41 | 'Currently during the initialization framework step.' |
|
| 42 | ); |
|
| 43 | ||
| 44 | $this->initStatus = true; |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||