@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * persistence implementation class |
|
| 4 | - */ |
|
| 3 | + * persistence implementation class |
|
| 4 | + */ |
|
| 5 | 5 | namespace Phile\Plugin\Phile\SimpleFileDataPersistence\Persistence; |
| 6 | 6 | |
| 7 | 7 | use Phile\ServiceLocator\PersistenceInterface; |
@@ -15,90 +15,90 @@ discard block |
||
| 15 | 15 | * @package Phile\Plugin\Phile\SimpleFileDataPersistence\Persistence |
| 16 | 16 | */ |
| 17 | 17 | class SimpleFileDataPersistence implements PersistenceInterface { |
| 18 | - /** @var string $dataDirectory the data storage directory */ |
|
| 19 | - protected $dataDirectory; |
|
| 18 | + /** @var string $dataDirectory the data storage directory */ |
|
| 19 | + protected $dataDirectory; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * the constructor |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - $this->dataDirectory = STORAGE_DIR; |
|
| 26 | - } |
|
| 21 | + /** |
|
| 22 | + * the constructor |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + $this->dataDirectory = STORAGE_DIR; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * check if key exists |
|
| 30 | - * |
|
| 31 | - * @param $key |
|
| 32 | - * |
|
| 33 | - * @return bool|mixed |
|
| 34 | - */ |
|
| 35 | - public function has($key) { |
|
| 36 | - return (file_exists($this->getStorageFile($key))); |
|
| 37 | - } |
|
| 28 | + /** |
|
| 29 | + * check if key exists |
|
| 30 | + * |
|
| 31 | + * @param $key |
|
| 32 | + * |
|
| 33 | + * @return bool|mixed |
|
| 34 | + */ |
|
| 35 | + public function has($key) { |
|
| 36 | + return (file_exists($this->getStorageFile($key))); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * get value for given key |
|
| 41 | - * |
|
| 42 | - * @param $key |
|
| 43 | - * |
|
| 44 | - * @return mixed |
|
| 45 | - * @throws \Phile\Exception\AbstractException |
|
| 46 | - */ |
|
| 47 | - public function get($key) { |
|
| 48 | - if (!$this->has($key)) { |
|
| 49 | - throw new \Phile\Exception\AbstractException("no data storage for key '{$key}' exists!"); |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * get value for given key |
|
| 41 | + * |
|
| 42 | + * @param $key |
|
| 43 | + * |
|
| 44 | + * @return mixed |
|
| 45 | + * @throws \Phile\Exception\AbstractException |
|
| 46 | + */ |
|
| 47 | + public function get($key) { |
|
| 48 | + if (!$this->has($key)) { |
|
| 49 | + throw new \Phile\Exception\AbstractException("no data storage for key '{$key}' exists!"); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return unserialize(file_get_contents($this->getStorageFile($key))); |
|
| 53 | - } |
|
| 52 | + return unserialize(file_get_contents($this->getStorageFile($key))); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * set value for given key |
|
| 57 | - * |
|
| 58 | - * @param $key |
|
| 59 | - * @param $value |
|
| 60 | - * |
|
| 61 | - * @return mixed|void |
|
| 62 | - */ |
|
| 63 | - public function set($key, $value) { |
|
| 64 | - file_put_contents($this->getStorageFile($key), serialize($value)); |
|
| 65 | - } |
|
| 55 | + /** |
|
| 56 | + * set value for given key |
|
| 57 | + * |
|
| 58 | + * @param $key |
|
| 59 | + * @param $value |
|
| 60 | + * |
|
| 61 | + * @return mixed|void |
|
| 62 | + */ |
|
| 63 | + public function set($key, $value) { |
|
| 64 | + file_put_contents($this->getStorageFile($key), serialize($value)); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * delte given key/index |
|
| 69 | - * |
|
| 70 | - * @param string $key |
|
| 71 | - * @param array $options |
|
| 72 | - * |
|
| 73 | - * @return mixed|void |
|
| 74 | - * @throws \Phile\Exception\AbstractException |
|
| 75 | - */ |
|
| 76 | - public function delete($key, array $options = array()) { |
|
| 77 | - if (!$this->has($key)) { |
|
| 78 | - throw new \Phile\Exception\AbstractException("no data storage for key '{$key}' exists!"); |
|
| 79 | - } |
|
| 80 | - unlink($this->getStorageFile($key)); |
|
| 81 | - } |
|
| 67 | + /** |
|
| 68 | + * delte given key/index |
|
| 69 | + * |
|
| 70 | + * @param string $key |
|
| 71 | + * @param array $options |
|
| 72 | + * |
|
| 73 | + * @return mixed|void |
|
| 74 | + * @throws \Phile\Exception\AbstractException |
|
| 75 | + */ |
|
| 76 | + public function delete($key, array $options = array()) { |
|
| 77 | + if (!$this->has($key)) { |
|
| 78 | + throw new \Phile\Exception\AbstractException("no data storage for key '{$key}' exists!"); |
|
| 79 | + } |
|
| 80 | + unlink($this->getStorageFile($key)); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * generate internal key |
|
| 85 | - * |
|
| 86 | - * @param $key |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - protected function getInternalKey($key) { |
|
| 91 | - return md5($key); |
|
| 92 | - } |
|
| 83 | + /** |
|
| 84 | + * generate internal key |
|
| 85 | + * |
|
| 86 | + * @param $key |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + protected function getInternalKey($key) { |
|
| 91 | + return md5($key); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * get storage filename |
|
| 96 | - * |
|
| 97 | - * @param $key |
|
| 98 | - * |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - protected function getStorageFile($key) { |
|
| 102 | - return $this->dataDirectory . $this->getInternalKey($key) . '.ds'; |
|
| 103 | - } |
|
| 94 | + /** |
|
| 95 | + * get storage filename |
|
| 96 | + * |
|
| 97 | + * @param $key |
|
| 98 | + * |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + protected function getStorageFile($key) { |
|
| 102 | + return $this->dataDirectory . $this->getInternalKey($key) . '.ds'; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Plugin class |
|
| 4 | - */ |
|
| 3 | + * Plugin class |
|
| 4 | + */ |
|
| 5 | 5 | namespace Phile\Plugin\Phile\SimpleFileDataPersistence; |
| 6 | 6 | |
| 7 | 7 | use Phile\Core\ServiceLocator; |
@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class Plugin extends AbstractPlugin { |
| 21 | 21 | |
| 22 | - protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 22 | + protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * onPluginsLoaded method |
|
| 26 | - * |
|
| 27 | - * @param null $data |
|
| 28 | - * |
|
| 29 | - * @return mixed|void |
|
| 30 | - */ |
|
| 31 | - public function onPluginsLoaded($data = null) { |
|
| 32 | - ServiceLocator::registerService('Phile_Data_Persistence', |
|
| 33 | - new SimpleFileDataPersistence()); |
|
| 34 | - } |
|
| 24 | + /** |
|
| 25 | + * onPluginsLoaded method |
|
| 26 | + * |
|
| 27 | + * @param null $data |
|
| 28 | + * |
|
| 29 | + * @return mixed|void |
|
| 30 | + */ |
|
| 31 | + public function onPluginsLoaded($data = null) { |
|
| 32 | + ServiceLocator::registerService('Phile_Data_Persistence', |
|
| 33 | + new SimpleFileDataPersistence()); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * config file |
|
| 4 | - */ |
|
| 3 | + * config file |
|
| 4 | + */ |
|
| 5 | 5 | $config = array(); |
| 6 | 6 | |
| 7 | 7 | return $config; |
| 8 | 8 | \ No newline at end of file |
@@ -18,20 +18,20 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Plugin extends AbstractPlugin { |
| 20 | 20 | |
| 21 | - protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 21 | + protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * onPluginsLoaded method |
|
| 25 | - */ |
|
| 26 | - public function onPluginsLoaded() { |
|
| 27 | - // phpFastCache not working in CLI mode... |
|
| 28 | - if (PHILE_CLI_MODE) { |
|
| 29 | - return; |
|
| 30 | - } |
|
| 31 | - unset($this->settings['active']); |
|
| 32 | - $config = $this->settings + \phpFastCache::$config; |
|
| 33 | - $storage = $this->settings['storage']; |
|
| 34 | - $cache = phpFastCache($storage, $config); |
|
| 35 | - ServiceLocator::registerService('Phile_Cache', new PhpFastCache($cache)); |
|
| 36 | - } |
|
| 23 | + /** |
|
| 24 | + * onPluginsLoaded method |
|
| 25 | + */ |
|
| 26 | + public function onPluginsLoaded() { |
|
| 27 | + // phpFastCache not working in CLI mode... |
|
| 28 | + if (PHILE_CLI_MODE) { |
|
| 29 | + return; |
|
| 30 | + } |
|
| 31 | + unset($this->settings['active']); |
|
| 32 | + $config = $this->settings + \phpFastCache::$config; |
|
| 33 | + $storage = $this->settings['storage']; |
|
| 34 | + $cache = phpFastCache($storage, $config); |
|
| 35 | + ServiceLocator::registerService('Phile_Cache', new PhpFastCache($cache)); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * The Error Handler |
|
| 4 | - */ |
|
| 3 | + * The Error Handler |
|
| 4 | + */ |
|
| 5 | 5 | |
| 6 | 6 | namespace Phile\Plugin\Phile\ErrorHandler; |
| 7 | 7 | use Phile\ServiceLocator\ErrorHandlerInterface; |
@@ -10,29 +10,29 @@ discard block |
||
| 10 | 10 | * Class ErrorLog |
| 11 | 11 | */ |
| 12 | 12 | class ErrorLog implements ErrorHandlerInterface { |
| 13 | - /** |
|
| 14 | - * handle the error |
|
| 15 | - * |
|
| 16 | - * @param int $errno |
|
| 17 | - * @param string $errstr |
|
| 18 | - * @param string $errfile |
|
| 19 | - * @param int $errline |
|
| 20 | - * @param array $errcontext |
|
| 21 | - * |
|
| 22 | - * @return boolean |
|
| 23 | - */ |
|
| 24 | - public function handleError($errno, $errstr, $errfile, $errline, array $errcontext) { |
|
| 25 | - error_log("[{$errno}] {$errstr} in {$errfile} on line {$errline}"); |
|
| 26 | - } |
|
| 13 | + /** |
|
| 14 | + * handle the error |
|
| 15 | + * |
|
| 16 | + * @param int $errno |
|
| 17 | + * @param string $errstr |
|
| 18 | + * @param string $errfile |
|
| 19 | + * @param int $errline |
|
| 20 | + * @param array $errcontext |
|
| 21 | + * |
|
| 22 | + * @return boolean |
|
| 23 | + */ |
|
| 24 | + public function handleError($errno, $errstr, $errfile, $errline, array $errcontext) { |
|
| 25 | + error_log("[{$errno}] {$errstr} in {$errfile} on line {$errline}"); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * handle all exceptions |
|
| 30 | - * |
|
| 31 | - * @param \Exception $exception |
|
| 32 | - * |
|
| 33 | - * @return mixed |
|
| 34 | - */ |
|
| 35 | - public function handleException(\Exception $exception) { |
|
| 36 | - error_log("[{$exception->getCode()}] {$exception->getMessage()} in {$exception->getFile()} on line {$exception->getLine()}"); |
|
| 37 | - } |
|
| 28 | + /** |
|
| 29 | + * handle all exceptions |
|
| 30 | + * |
|
| 31 | + * @param \Exception $exception |
|
| 32 | + * |
|
| 33 | + * @return mixed |
|
| 34 | + */ |
|
| 35 | + public function handleException(\Exception $exception) { |
|
| 36 | + error_log("[{$exception->getCode()}] {$exception->getMessage()} in {$exception->getFile()} on line {$exception->getLine()}"); |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -20,8 +20,8 @@ |
||
| 20 | 20 | * @package Phile\Plugin\Phile\ParserMarkdown |
| 21 | 21 | */ |
| 22 | 22 | class Plugin extends AbstractPlugin { |
| 23 | - const HANDLER_ERROR_LOG = 'error_log'; |
|
| 24 | - const HANDLER_DEVELOPMENT = 'development'; |
|
| 23 | + const HANDLER_ERROR_LOG = 'error_log'; |
|
| 24 | + const HANDLER_DEVELOPMENT = 'development'; |
|
| 25 | 25 | |
| 26 | 26 | protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
| 27 | 27 | |
@@ -20,28 +20,28 @@ |
||
| 20 | 20 | * @package Phile\Plugin\Phile\ParserMarkdown |
| 21 | 21 | */ |
| 22 | 22 | class Plugin extends AbstractPlugin { |
| 23 | - const HANDLER_ERROR_LOG = 'error_log'; |
|
| 24 | - const HANDLER_DEVELOPMENT = 'development'; |
|
| 23 | + const HANDLER_ERROR_LOG = 'error_log'; |
|
| 24 | + const HANDLER_DEVELOPMENT = 'development'; |
|
| 25 | 25 | |
| 26 | - protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 26 | + protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * called on 'plugins_loaded' event |
|
| 30 | - * |
|
| 31 | - * @param null $data |
|
| 32 | - * @throws \Phile\Exception\ServiceLocatorException |
|
| 33 | - */ |
|
| 34 | - public function onPluginsLoaded($data = null) { |
|
| 35 | - $this->settings['base_url'] = (new Router)->getBaseUrl(); |
|
| 36 | - switch ($this->settings['handler']) { |
|
| 37 | - case Plugin::HANDLER_ERROR_LOG: |
|
| 38 | - ServiceLocator::registerService('Phile_ErrorHandler', |
|
| 39 | - new ErrorLog($this->settings)); |
|
| 40 | - break; |
|
| 41 | - case Plugin::HANDLER_DEVELOPMENT: |
|
| 42 | - ServiceLocator::registerService('Phile_ErrorHandler', |
|
| 43 | - new Development($this->settings)); |
|
| 44 | - break; |
|
| 45 | - } |
|
| 46 | - } |
|
| 28 | + /** |
|
| 29 | + * called on 'plugins_loaded' event |
|
| 30 | + * |
|
| 31 | + * @param null $data |
|
| 32 | + * @throws \Phile\Exception\ServiceLocatorException |
|
| 33 | + */ |
|
| 34 | + public function onPluginsLoaded($data = null) { |
|
| 35 | + $this->settings['base_url'] = (new Router)->getBaseUrl(); |
|
| 36 | + switch ($this->settings['handler']) { |
|
| 37 | + case Plugin::HANDLER_ERROR_LOG: |
|
| 38 | + ServiceLocator::registerService('Phile_ErrorHandler', |
|
| 39 | + new ErrorLog($this->settings)); |
|
| 40 | + break; |
|
| 41 | + case Plugin::HANDLER_DEVELOPMENT: |
|
| 42 | + ServiceLocator::registerService('Phile_ErrorHandler', |
|
| 43 | + new Development($this->settings)); |
|
| 44 | + break; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -1,8 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * the configuration file |
|
| 4 | - */ |
|
| 3 | + * the configuration file |
|
| 4 | + */ |
|
| 5 | 5 | |
| 6 | 6 | return array( |
| 7 | - 'handler' => \Phile\Plugin\Phile\ErrorHandler\Plugin::HANDLER_ERROR_LOG |
|
| 7 | + 'handler' => \Phile\Plugin\Phile\ErrorHandler\Plugin::HANDLER_ERROR_LOG |
|
| 8 | 8 | ); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Plugin class |
|
| 4 | - */ |
|
| 3 | + * Plugin class |
|
| 4 | + */ |
|
| 5 | 5 | namespace Phile\Plugin\Phile\ParserMeta; |
| 6 | 6 | |
| 7 | 7 | use Phile\Core\ServiceLocator; |
@@ -19,18 +19,18 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class Plugin extends AbstractPlugin { |
| 21 | 21 | |
| 22 | - protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 22 | + protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * onPluginsLoaded method |
|
| 26 | - * |
|
| 27 | - * @param null $data |
|
| 28 | - * |
|
| 29 | - * @return mixed|void |
|
| 30 | - */ |
|
| 31 | - public function onPluginsLoaded($data = null) { |
|
| 32 | - ServiceLocator::registerService('Phile_Parser_Meta', |
|
| 33 | - new Meta($this->settings)); |
|
| 34 | - } |
|
| 24 | + /** |
|
| 25 | + * onPluginsLoaded method |
|
| 26 | + * |
|
| 27 | + * @param null $data |
|
| 28 | + * |
|
| 29 | + * @return mixed|void |
|
| 30 | + */ |
|
| 31 | + public function onPluginsLoaded($data = null) { |
|
| 32 | + ServiceLocator::registerService('Phile_Parser_Meta', |
|
| 33 | + new Meta($this->settings)); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
@@ -16,97 +16,97 @@ |
||
| 16 | 16 | * @package Phile\Plugin\Phile\ParserMeta\Parser |
| 17 | 17 | */ |
| 18 | 18 | class Meta implements MetaInterface { |
| 19 | - /** @var array $config the configuration for this parser */ |
|
| 20 | - private $config; |
|
| 19 | + /** @var array $config the configuration for this parser */ |
|
| 20 | + private $config; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * the constructor |
|
| 24 | - * |
|
| 25 | - * @param array $config |
|
| 26 | - */ |
|
| 27 | - public function __construct(array $config = null) { |
|
| 28 | - if (!is_null($config)) { |
|
| 29 | - $this->config = $config; |
|
| 30 | - } |
|
| 31 | - } |
|
| 22 | + /** |
|
| 23 | + * the constructor |
|
| 24 | + * |
|
| 25 | + * @param array $config |
|
| 26 | + */ |
|
| 27 | + public function __construct(array $config = null) { |
|
| 28 | + if (!is_null($config)) { |
|
| 29 | + $this->config = $config; |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * parse the content and extract meta information |
|
| 35 | - * |
|
| 36 | - * @param string $rawData raw page data |
|
| 37 | - * @return array with key/value store |
|
| 38 | - */ |
|
| 39 | - public function parse($rawData) { |
|
| 40 | - $rawData = trim($rawData); |
|
| 33 | + /** |
|
| 34 | + * parse the content and extract meta information |
|
| 35 | + * |
|
| 36 | + * @param string $rawData raw page data |
|
| 37 | + * @return array with key/value store |
|
| 38 | + */ |
|
| 39 | + public function parse($rawData) { |
|
| 40 | + $rawData = trim($rawData); |
|
| 41 | 41 | |
| 42 | - $start = substr($rawData, 0, 4); |
|
| 43 | - if ($start === '<!--') { |
|
| 44 | - $stop = '-->'; |
|
| 45 | - } elseif (substr($start, 0, 2) === '/*') { |
|
| 46 | - $start = '/*'; |
|
| 47 | - $stop = '*/'; |
|
| 48 | - } else { |
|
| 49 | - return []; |
|
| 50 | - } |
|
| 42 | + $start = substr($rawData, 0, 4); |
|
| 43 | + if ($start === '<!--') { |
|
| 44 | + $stop = '-->'; |
|
| 45 | + } elseif (substr($start, 0, 2) === '/*') { |
|
| 46 | + $start = '/*'; |
|
| 47 | + $stop = '*/'; |
|
| 48 | + } else { |
|
| 49 | + return []; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $meta = trim(substr($rawData, strlen($start), strpos($rawData, $stop) - (strlen($stop) + 1))); |
|
| 53 | - if (strtolower($this->config['format']) === 'yaml') { |
|
| 54 | - $meta = Yaml::parse($meta); |
|
| 55 | - } else { |
|
| 56 | - $meta = $this->parsePhileFormat($meta); |
|
| 57 | - } |
|
| 58 | - $meta = ($meta === null) ? [] : $this->convertKeys($meta); |
|
| 59 | - return $meta; |
|
| 60 | - } |
|
| 52 | + $meta = trim(substr($rawData, strlen($start), strpos($rawData, $stop) - (strlen($stop) + 1))); |
|
| 53 | + if (strtolower($this->config['format']) === 'yaml') { |
|
| 54 | + $meta = Yaml::parse($meta); |
|
| 55 | + } else { |
|
| 56 | + $meta = $this->parsePhileFormat($meta); |
|
| 57 | + } |
|
| 58 | + $meta = ($meta === null) ? [] : $this->convertKeys($meta); |
|
| 59 | + return $meta; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * convert meta data keys |
|
| 64 | - * |
|
| 65 | - * Creates "compatible" keys allowing easy access e.g. as template var. |
|
| 66 | - * |
|
| 67 | - * Conversions applied: |
|
| 68 | - * |
|
| 69 | - * - lowercase all chars |
|
| 70 | - * - replace special chars and whitespace with underscore |
|
| 71 | - * |
|
| 72 | - * @param array $meta meta-data |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - protected function convertKeys(array $meta) { |
|
| 76 | - $return = []; |
|
| 77 | - foreach ($meta as $key => $value) { |
|
| 78 | - if (is_array($value)) { |
|
| 79 | - $value = $this->convertKeys($value); |
|
| 80 | - } |
|
| 81 | - $newKey = strtolower($key); |
|
| 82 | - $newKey = preg_replace('/[^\w+]/', '_', $newKey); |
|
| 83 | - $return[$newKey] = $value; |
|
| 84 | - } |
|
| 85 | - return $return; |
|
| 86 | - } |
|
| 62 | + /** |
|
| 63 | + * convert meta data keys |
|
| 64 | + * |
|
| 65 | + * Creates "compatible" keys allowing easy access e.g. as template var. |
|
| 66 | + * |
|
| 67 | + * Conversions applied: |
|
| 68 | + * |
|
| 69 | + * - lowercase all chars |
|
| 70 | + * - replace special chars and whitespace with underscore |
|
| 71 | + * |
|
| 72 | + * @param array $meta meta-data |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + protected function convertKeys(array $meta) { |
|
| 76 | + $return = []; |
|
| 77 | + foreach ($meta as $key => $value) { |
|
| 78 | + if (is_array($value)) { |
|
| 79 | + $value = $this->convertKeys($value); |
|
| 80 | + } |
|
| 81 | + $newKey = strtolower($key); |
|
| 82 | + $newKey = preg_replace('/[^\w+]/', '_', $newKey); |
|
| 83 | + $return[$newKey] = $value; |
|
| 84 | + } |
|
| 85 | + return $return; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Phile meta format parser. |
|
| 90 | - * |
|
| 91 | - * @param string $string unparsed meta-data |
|
| 92 | - * @return array|null array with meta-tags; null: on meta-data found |
|
| 93 | - * |
|
| 94 | - * @deprecated since 1.6.0 Phile is going to switch to YAML |
|
| 95 | - */ |
|
| 96 | - protected function parsePhileFormat($string) { |
|
| 97 | - if (empty($string)) { |
|
| 98 | - return null; |
|
| 99 | - } |
|
| 100 | - $meta = []; |
|
| 101 | - $lines = explode("\n", $string); |
|
| 102 | - foreach ($lines as $line) { |
|
| 103 | - $parts = explode(':', $line, 2); |
|
| 104 | - if (count($parts) !== 2) { |
|
| 105 | - continue; |
|
| 106 | - } |
|
| 107 | - $parts = array_map('trim', $parts); |
|
| 108 | - $meta[$parts[0]] = $parts[1]; |
|
| 109 | - } |
|
| 110 | - return $meta; |
|
| 111 | - } |
|
| 88 | + /** |
|
| 89 | + * Phile meta format parser. |
|
| 90 | + * |
|
| 91 | + * @param string $string unparsed meta-data |
|
| 92 | + * @return array|null array with meta-tags; null: on meta-data found |
|
| 93 | + * |
|
| 94 | + * @deprecated since 1.6.0 Phile is going to switch to YAML |
|
| 95 | + */ |
|
| 96 | + protected function parsePhileFormat($string) { |
|
| 97 | + if (empty($string)) { |
|
| 98 | + return null; |
|
| 99 | + } |
|
| 100 | + $meta = []; |
|
| 101 | + $lines = explode("\n", $string); |
|
| 102 | + foreach ($lines as $line) { |
|
| 103 | + $parts = explode(':', $line, 2); |
|
| 104 | + if (count($parts) !== 2) { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 107 | + $parts = array_map('trim', $parts); |
|
| 108 | + $meta[$parts[0]] = $parts[1]; |
|
| 109 | + } |
|
| 110 | + return $meta; |
|
| 111 | + } |
|
| 112 | 112 | } |