@@ -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 |
@@ -13,73 +13,73 @@ |
||
| 13 | 13 | * @package Phile\Plugin\Phile\PhpFastCache |
| 14 | 14 | */ |
| 15 | 15 | class PhpFastCache implements \Phile\ServiceLocator\CacheInterface { |
| 16 | - /** |
|
| 17 | - * @var \BasePhpFastCache the cache engine |
|
| 18 | - */ |
|
| 19 | - protected $cacheEngine; |
|
| 16 | + /** |
|
| 17 | + * @var \BasePhpFastCache the cache engine |
|
| 18 | + */ |
|
| 19 | + protected $cacheEngine; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * the constructor |
|
| 23 | - * |
|
| 24 | - * @param \BasePhpFastCache $cacheEngine |
|
| 25 | - */ |
|
| 26 | - public function __construct(\BasePhpFastCache $cacheEngine) { |
|
| 27 | - $this->cacheEngine = $cacheEngine; |
|
| 28 | - } |
|
| 21 | + /** |
|
| 22 | + * the constructor |
|
| 23 | + * |
|
| 24 | + * @param \BasePhpFastCache $cacheEngine |
|
| 25 | + */ |
|
| 26 | + public function __construct(\BasePhpFastCache $cacheEngine) { |
|
| 27 | + $this->cacheEngine = $cacheEngine; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * method to check if cache has entry for given key |
|
| 32 | - * |
|
| 33 | - * @param $key |
|
| 34 | - * |
|
| 35 | - * @return bool|mixed |
|
| 36 | - */ |
|
| 37 | - public function has($key) { |
|
| 38 | - return ($this->cacheEngine->get($key) !== null); |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * method to check if cache has entry for given key |
|
| 32 | + * |
|
| 33 | + * @param $key |
|
| 34 | + * |
|
| 35 | + * @return bool|mixed |
|
| 36 | + */ |
|
| 37 | + public function has($key) { |
|
| 38 | + return ($this->cacheEngine->get($key) !== null); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * method to get cache entry |
|
| 43 | - * |
|
| 44 | - * @param $key |
|
| 45 | - * |
|
| 46 | - * @return mixed|null |
|
| 47 | - */ |
|
| 48 | - public function get($key) { |
|
| 49 | - return $this->cacheEngine->get($key); |
|
| 50 | - } |
|
| 41 | + /** |
|
| 42 | + * method to get cache entry |
|
| 43 | + * |
|
| 44 | + * @param $key |
|
| 45 | + * |
|
| 46 | + * @return mixed|null |
|
| 47 | + */ |
|
| 48 | + public function get($key) { |
|
| 49 | + return $this->cacheEngine->get($key); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * method to set cache entry |
|
| 54 | - * |
|
| 55 | - * @param string $key |
|
| 56 | - * @param string $value |
|
| 57 | - * @param int $time |
|
| 58 | - * @param array $options |
|
| 59 | - * |
|
| 60 | - * @return mixed|void |
|
| 61 | - */ |
|
| 62 | - public function set($key, $value, $time = 300, array $options = array()) { |
|
| 63 | - $this->cacheEngine->set($key, $value, $time, $options); |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * method to set cache entry |
|
| 54 | + * |
|
| 55 | + * @param string $key |
|
| 56 | + * @param string $value |
|
| 57 | + * @param int $time |
|
| 58 | + * @param array $options |
|
| 59 | + * |
|
| 60 | + * @return mixed|void |
|
| 61 | + */ |
|
| 62 | + public function set($key, $value, $time = 300, array $options = array()) { |
|
| 63 | + $this->cacheEngine->set($key, $value, $time, $options); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * method to delete cache entry |
|
| 68 | - * |
|
| 69 | - * @param string $key |
|
| 70 | - * @param array $options |
|
| 71 | - * |
|
| 72 | - * @return mixed|void |
|
| 73 | - */ |
|
| 74 | - public function delete($key, array $options = array()) { |
|
| 75 | - $this->cacheEngine->delete($key, $options); |
|
| 76 | - } |
|
| 66 | + /** |
|
| 67 | + * method to delete cache entry |
|
| 68 | + * |
|
| 69 | + * @param string $key |
|
| 70 | + * @param array $options |
|
| 71 | + * |
|
| 72 | + * @return mixed|void |
|
| 73 | + */ |
|
| 74 | + public function delete($key, array $options = array()) { |
|
| 75 | + $this->cacheEngine->delete($key, $options); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * clean complete cache and delete all cached entries |
|
| 80 | - */ |
|
| 81 | - public function clean() { |
|
| 82 | - $this->cacheEngine->clean(); |
|
| 83 | - } |
|
| 78 | + /** |
|
| 79 | + * clean complete cache and delete all cached entries |
|
| 80 | + */ |
|
| 81 | + public function clean() { |
|
| 82 | + $this->cacheEngine->clean(); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
@@ -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,50 +1,50 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * config file for plugin |
|
| 4 | - */ |
|
| 3 | + * config file for plugin |
|
| 4 | + */ |
|
| 5 | 5 | $config = [ |
| 6 | - /** |
|
| 7 | - * Default storage engine |
|
| 8 | - * |
|
| 9 | - * e.g. "files": $cache = phpFastCache(); <-- will be files cache |
|
| 10 | - * |
|
| 11 | - * auto, files, sqlite, auto, apc, wincache, xcache, memcache, memcached, |
|
| 12 | - */ |
|
| 13 | - 'storage' => 'auto', |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * Default Path for File Cache |
|
| 17 | - * |
|
| 18 | - * Use full PATH like /home/username/cache |
|
| 19 | - * Keep it blank "", it will automatic setup for you |
|
| 20 | - */ |
|
| 21 | - 'path' => CACHE_DIR, |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Permissions for file storage |
|
| 25 | - */ |
|
| 6 | + /** |
|
| 7 | + * Default storage engine |
|
| 8 | + * |
|
| 9 | + * e.g. "files": $cache = phpFastCache(); <-- will be files cache |
|
| 10 | + * |
|
| 11 | + * auto, files, sqlite, auto, apc, wincache, xcache, memcache, memcached, |
|
| 12 | + */ |
|
| 13 | + 'storage' => 'auto', |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * Default Path for File Cache |
|
| 17 | + * |
|
| 18 | + * Use full PATH like /home/username/cache |
|
| 19 | + * Keep it blank "", it will automatic setup for you |
|
| 20 | + */ |
|
| 21 | + 'path' => CACHE_DIR, |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Permissions for file storage |
|
| 25 | + */ |
|
| 26 | 26 | // 'default_chmod' => 0777, // For security, please use 0666 for module and 0644 for cgi. |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | // "securityKey" => "auto", // default will good. It will create a path by PATH/securityKey |
| 30 | 30 | |
| 31 | - /* |
|
| 31 | + /* |
|
| 32 | 32 | * FallBack Driver |
| 33 | 33 | * Example, in your code, you use memcached, apc..etc, but when you moved your web hosting |
| 34 | 34 | * The new hosting don't have memcached, or apc. What you do? Set fallback that driver to other driver. |
| 35 | 35 | */ |
| 36 | 36 | // "fallback" => "files", |
| 37 | 37 | |
| 38 | - /* |
|
| 38 | + /* |
|
| 39 | 39 | * .htaccess protect |
| 40 | 40 | * default will be true |
| 41 | 41 | */ |
| 42 | 42 | // "htaccess" => true, |
| 43 | 43 | |
| 44 | - /* |
|
| 44 | + /* |
|
| 45 | 45 | * Default Memcache Server for all $cache = phpFastCache("memcache"); |
| 46 | 46 | */ |
| 47 | - /* |
|
| 47 | + /* |
|
| 48 | 48 | "memcache" => array( |
| 49 | 49 | array("127.0.0.1",11211,1), |
| 50 | 50 | // array("new.host.ip",11211,1), |
@@ -18,79 +18,79 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Plugin extends AbstractPlugin { |
| 20 | 20 | |
| 21 | - /** @var global Phile config */ |
|
| 22 | - protected $config; |
|
| 21 | + /** @var global Phile config */ |
|
| 22 | + protected $config; |
|
| 23 | 23 | |
| 24 | - /** @var bool Phile installation needs setup */ |
|
| 25 | - protected $needsSetup = true; |
|
| 24 | + /** @var bool Phile installation needs setup */ |
|
| 25 | + protected $needsSetup = true; |
|
| 26 | 26 | |
| 27 | - /** @var array event subscription */ |
|
| 28 | - protected $events = [ |
|
| 29 | - 'config_loaded' => 'onConfigLoaded', |
|
| 30 | - 'setup_check' => 'onSetupCheck', |
|
| 31 | - 'after_render_template' => 'onAfterRenderTemplate' |
|
| 32 | - ]; |
|
| 27 | + /** @var array event subscription */ |
|
| 28 | + protected $events = [ |
|
| 29 | + 'config_loaded' => 'onConfigLoaded', |
|
| 30 | + 'setup_check' => 'onSetupCheck', |
|
| 31 | + 'after_render_template' => 'onAfterRenderTemplate' |
|
| 32 | + ]; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * get global config |
|
| 36 | - * |
|
| 37 | - * @param array $eventData |
|
| 38 | - */ |
|
| 39 | - protected function onConfigLoaded(array $eventData) { |
|
| 40 | - $this->config = $eventData['config']; |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * get global config |
|
| 36 | + * |
|
| 37 | + * @param array $eventData |
|
| 38 | + */ |
|
| 39 | + protected function onConfigLoaded(array $eventData) { |
|
| 40 | + $this->config = $eventData['config']; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * perform setup check |
|
| 45 | - */ |
|
| 46 | - protected function onSetupCheck() { |
|
| 47 | - if (empty($this->config['encryptionKey'])) { |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - $this->needsSetup = false; |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * perform setup check |
|
| 45 | + */ |
|
| 46 | + protected function onSetupCheck() { |
|
| 47 | + if (empty($this->config['encryptionKey'])) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | + $this->needsSetup = false; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * render setup message |
|
| 55 | - * |
|
| 56 | - * @param array $eventData |
|
| 57 | - */ |
|
| 58 | - protected function onAfterRenderTemplate(array $eventData) { |
|
| 59 | - if (!$this->needsSetup) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 62 | - $engine = $eventData['templateEngine']; |
|
| 53 | + /** |
|
| 54 | + * render setup message |
|
| 55 | + * |
|
| 56 | + * @param array $eventData |
|
| 57 | + */ |
|
| 58 | + protected function onAfterRenderTemplate(array $eventData) { |
|
| 59 | + if (!$this->needsSetup) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | + $engine = $eventData['templateEngine']; |
|
| 63 | 63 | |
| 64 | - $page = new Page($this->getPluginPath('setup.md')); |
|
| 65 | - $vars = ['encryption_key' => $this->generateToken()]; |
|
| 66 | - $this->insertVars($page, $vars); |
|
| 64 | + $page = new Page($this->getPluginPath('setup.md')); |
|
| 65 | + $vars = ['encryption_key' => $this->generateToken()]; |
|
| 66 | + $this->insertVars($page, $vars); |
|
| 67 | 67 | |
| 68 | - $engine->setCurrentPage($page); |
|
| 69 | - $eventData['output'] = $engine->render(); |
|
| 70 | - } |
|
| 68 | + $engine->setCurrentPage($page); |
|
| 69 | + $eventData['output'] = $engine->render(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * replace twig like variables in page content |
|
| 74 | - * |
|
| 75 | - * @param Page $page |
|
| 76 | - * @param array $vars |
|
| 77 | - */ |
|
| 78 | - protected function insertVars(Page $page, array $vars) { |
|
| 79 | - $content = $page->getRawContent(); |
|
| 80 | - foreach ($vars as $key => $value) { |
|
| 81 | - $regex = '/\{\{(\s*?)' . $key . '(\s*?)\}\}/'; |
|
| 82 | - $content = preg_replace($regex, $value, $content); |
|
| 83 | - } |
|
| 84 | - $page->setContent($content); |
|
| 85 | - } |
|
| 72 | + /** |
|
| 73 | + * replace twig like variables in page content |
|
| 74 | + * |
|
| 75 | + * @param Page $page |
|
| 76 | + * @param array $vars |
|
| 77 | + */ |
|
| 78 | + protected function insertVars(Page $page, array $vars) { |
|
| 79 | + $content = $page->getRawContent(); |
|
| 80 | + foreach ($vars as $key => $value) { |
|
| 81 | + $regex = '/\{\{(\s*?)' . $key . '(\s*?)\}\}/'; |
|
| 82 | + $content = preg_replace($regex, $value, $content); |
|
| 83 | + } |
|
| 84 | + $page->setContent($content); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * generate encryption key |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - protected function generateToken() { |
|
| 93 | - return Utility::generateSecureToken(64); |
|
| 94 | - } |
|
| 87 | + /** |
|
| 88 | + * generate encryption key |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + protected function generateToken() { |
|
| 93 | + return Utility::generateSecureToken(64); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | } |
@@ -18,281 +18,281 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Development implements ErrorHandlerInterface { |
| 20 | 20 | |
| 21 | - /** @var array settings */ |
|
| 22 | - protected $settings; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * constructor |
|
| 26 | - * |
|
| 27 | - * @param array $settings |
|
| 28 | - */ |
|
| 29 | - public function __construct(array $settings = []) { |
|
| 30 | - $this->settings = $settings; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * handle the error |
|
| 35 | - * |
|
| 36 | - * @param int $errno |
|
| 37 | - * @param string $errstr |
|
| 38 | - * @param string $errfile |
|
| 39 | - * @param int $errline |
|
| 40 | - * @param array $errcontext |
|
| 41 | - * |
|
| 42 | - * @return boolean |
|
| 43 | - */ |
|
| 44 | - public function handleError($errno, $errstr, $errfile, $errline, array $errcontext) { |
|
| 45 | - $backtrace = debug_backtrace(); |
|
| 46 | - $backtrace = array_slice($backtrace, 2); |
|
| 47 | - $this->displayDeveloperOutput( |
|
| 48 | - $errno, |
|
| 49 | - $errstr, |
|
| 50 | - $errfile, |
|
| 51 | - $errline, |
|
| 52 | - $backtrace |
|
| 53 | - ); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * handle PHP errors which can't be caught by error-handler |
|
| 58 | - */ |
|
| 59 | - public function handleShutdown() { |
|
| 60 | - $error = error_get_last(); |
|
| 61 | - if ($error === null) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - $this->displayDeveloperOutput( |
|
| 65 | - $error['type'], |
|
| 66 | - $error['message'], |
|
| 67 | - $error['file'], |
|
| 68 | - $error['line'] |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * handle all exceptions |
|
| 74 | - * |
|
| 75 | - * @param \Exception $exception |
|
| 76 | - * |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - public function handleException(\Exception $exception) { |
|
| 80 | - $this->displayDeveloperOutput( |
|
| 81 | - $exception->getCode(), |
|
| 82 | - $exception->getMessage(), |
|
| 83 | - $exception->getFile(), |
|
| 84 | - $exception->getLine(), |
|
| 85 | - null, |
|
| 86 | - $exception |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * show a nice looking and human readable developer output |
|
| 92 | - * |
|
| 93 | - * @param $code |
|
| 94 | - * @param $message |
|
| 95 | - * @param $file |
|
| 96 | - * @param $line |
|
| 97 | - * @param \Exception $exception |
|
| 98 | - */ |
|
| 99 | - protected function displayDeveloperOutput($code, $message, $file, $line, array $backtrace = null, \Exception $exception = null) { |
|
| 100 | - header('HTTP/1.1 500 Internal Server Error'); |
|
| 101 | - $fragment = $this->receiveCodeFragment($file, |
|
| 102 | - $line, 5, 5); |
|
| 103 | - $marker = [ |
|
| 104 | - 'base_url' => $this->settings['base_url'], |
|
| 105 | - 'type' => $exception ? 'Exception' : 'Error', |
|
| 106 | - 'exception_message' => htmlspecialchars($message), |
|
| 107 | - 'exception_code' => htmlspecialchars($code), |
|
| 108 | - 'exception_file' => htmlspecialchars($file), |
|
| 109 | - 'exception_line' => htmlspecialchars($line), |
|
| 110 | - 'exception_fragment' => $fragment, |
|
| 111 | - 'exception_class' => '', |
|
| 112 | - 'wiki_link' => '' |
|
| 113 | - ]; |
|
| 114 | - |
|
| 115 | - if ($exception) { |
|
| 116 | - $marker['exception_class'] = $this->linkClass(get_class($exception)); |
|
| 117 | - $marker['wiki_link'] = ($code > 0) ? '(<a href="https://github.com/PhileCMS/Phile/wiki/Exception_' . $code . '" target="_blank">Exception-Wiki</a>)' : ''; |
|
| 118 | - $backtrace = $exception->getTrace(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($backtrace) { |
|
| 122 | - $marker['exception_backtrace'] = $this->createBacktrace($backtrace); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $DS = DIRECTORY_SEPARATOR; |
|
| 126 | - $pluginPath = realpath(dirname(__FILE__) . $DS . '..') . $DS; |
|
| 127 | - $tplPath = $pluginPath . 'template.php'; |
|
| 128 | - |
|
| 129 | - ob_start(); |
|
| 130 | - extract($marker); |
|
| 131 | - include $tplPath; |
|
| 132 | - ob_end_flush(); |
|
| 133 | - die(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * creates a human readable backtrace |
|
| 138 | - * |
|
| 139 | - * @param array $traces |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - protected function createBacktrace(array $traces) { |
|
| 143 | - if (!count($traces)) { |
|
| 144 | - return ''; |
|
| 145 | - } |
|
| 146 | - $backtraceCodes = []; |
|
| 147 | - |
|
| 148 | - foreach ($traces as $index => $step) { |
|
| 149 | - $backtrace = $this->tag('span', count($traces) - $index, ['class' => 'index']); |
|
| 150 | - $backtrace .= ' '; |
|
| 151 | - |
|
| 152 | - if (isset($step['class'])) { |
|
| 153 | - $class = $this->linkClass($step['class']) . '<span class="divider">::</span>'; |
|
| 154 | - $backtrace .= $class . $this->linkClass($step['class'], $step['function']); |
|
| 155 | - } elseif (isset($step['function'])) { |
|
| 156 | - $backtrace .= $this->tag('span', $step['function'], ['class' => 'function']); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $arguments = $this->getBacktraceStepArguments($step); |
|
| 160 | - if ($arguments) { |
|
| 161 | - $backtrace .= $this->tag('span', "($arguments)", ['class' => 'funcArguments']); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if (isset($step['file'])) { |
|
| 165 | - $backtrace .= $this->receiveCodeFragment($step['file'], $step['line'], 3, 3); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $backtraceCodes[] = $this->tag('pre', $backtrace, ['class' => 'entry']); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return implode('', $backtraceCodes); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * render arguments for backtrace step |
|
| 177 | - * |
|
| 178 | - * @param $step |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - protected function getBacktraceStepArguments($step) { |
|
| 182 | - if (empty($step['args'])) { |
|
| 183 | - return ''; |
|
| 184 | - } |
|
| 185 | - $arguments = ''; |
|
| 186 | - foreach ($step['args'] as $argument) { |
|
| 187 | - $arguments .= strlen($arguments) === 0 ? '' : $this->tag('span', ', ', ['class' => 'separator']); |
|
| 188 | - if (is_object($argument)) { |
|
| 189 | - $class = 'class'; |
|
| 190 | - $content = $this->linkClass(get_class($argument)); |
|
| 191 | - } else { |
|
| 192 | - $class = 'others'; |
|
| 193 | - $content = gettype($argument); |
|
| 194 | - } |
|
| 195 | - $arguments .= $this->tag( |
|
| 196 | - 'span', |
|
| 197 | - $content, |
|
| 198 | - [ |
|
| 199 | - 'class' => $class, |
|
| 200 | - 'title' => print_r($argument, true) |
|
| 201 | - ] |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - return $arguments; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * receive a code fragment from file |
|
| 209 | - * |
|
| 210 | - * @param $filename |
|
| 211 | - * @param $lineNumber |
|
| 212 | - * @param $linesBefore |
|
| 213 | - * @param $linesAfter |
|
| 214 | - * |
|
| 215 | - * @return string |
|
| 216 | - */ |
|
| 217 | - protected function receiveCodeFragment($filename, $lineNumber, $linesBefore = 3, $linesAfter = 3) { |
|
| 218 | - if (!file_exists($filename)) { |
|
| 219 | - return ''; |
|
| 220 | - } |
|
| 221 | - $html = $this->tag('span', $filename . ':<br/>', ['class' => 'filename']); |
|
| 222 | - |
|
| 223 | - $code = file_get_contents($filename); |
|
| 224 | - $lines = explode("\n", $code); |
|
| 225 | - |
|
| 226 | - $firstLine = $lineNumber - $linesBefore - 1; |
|
| 227 | - if ($firstLine < 0) { |
|
| 228 | - $firstLine = 0; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $lastLine = $lineNumber + $linesAfter; |
|
| 232 | - if ($lastLine > count($lines)) { |
|
| 233 | - $lastLine = count($lines); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $line = $firstLine; |
|
| 237 | - $fragment = ''; |
|
| 238 | - while ($line < $lastLine) { |
|
| 239 | - $line++; |
|
| 240 | - |
|
| 241 | - $lineText = htmlspecialchars($lines[$line - 1]); |
|
| 242 | - $lineText = str_replace("\t", ' ', $lineText); |
|
| 243 | - $tmp = sprintf('%05d: %s <br/>', $line, $lineText); |
|
| 244 | - |
|
| 245 | - $class = 'row'; |
|
| 246 | - if ($line === $lineNumber) { |
|
| 247 | - $class .= ' currentRow'; |
|
| 248 | - } |
|
| 249 | - $fragment .= $this->tag('span', $tmp, ['class' => $class]); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - $html .= $fragment; |
|
| 254 | - return $this->tag('pre', $html); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * link the class or method to the API or return the method name |
|
| 259 | - * @param $class |
|
| 260 | - * @param $method |
|
| 261 | - * |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - protected function linkClass($class, $method = null) { |
|
| 265 | - $title = $method ? $method : $class; |
|
| 266 | - if (strpos($class, 'Phile\\') === 0) { |
|
| 267 | - return $title; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $filename = 'docs/classes/' . str_replace('\\', '.', $class) . '.html'; |
|
| 271 | - if (file_exists(Utility::resolveFilePath($filename))) { |
|
| 272 | - return $title; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $href = $this->settings['base_url'] . '/' . $filename; |
|
| 276 | - if ($method) { |
|
| 277 | - $href .= '#method_' . $method; |
|
| 278 | - } |
|
| 279 | - return $this->tag('a', $title, ['href' => $href, 'target' => '_blank']); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * create HTML-tag |
|
| 284 | - * |
|
| 285 | - * @param string $tag |
|
| 286 | - * @param string $content |
|
| 287 | - * @param array $attributes |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - protected function tag($tag, $content = '', array $attributes = []) { |
|
| 291 | - $html = '<' . $tag; |
|
| 292 | - foreach ($attributes as $key => $value) { |
|
| 293 | - $html .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; |
|
| 294 | - } |
|
| 295 | - $html .= '>' . $content . '</' . $tag . '>'; |
|
| 296 | - return $html; |
|
| 297 | - } |
|
| 21 | + /** @var array settings */ |
|
| 22 | + protected $settings; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * constructor |
|
| 26 | + * |
|
| 27 | + * @param array $settings |
|
| 28 | + */ |
|
| 29 | + public function __construct(array $settings = []) { |
|
| 30 | + $this->settings = $settings; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * handle the error |
|
| 35 | + * |
|
| 36 | + * @param int $errno |
|
| 37 | + * @param string $errstr |
|
| 38 | + * @param string $errfile |
|
| 39 | + * @param int $errline |
|
| 40 | + * @param array $errcontext |
|
| 41 | + * |
|
| 42 | + * @return boolean |
|
| 43 | + */ |
|
| 44 | + public function handleError($errno, $errstr, $errfile, $errline, array $errcontext) { |
|
| 45 | + $backtrace = debug_backtrace(); |
|
| 46 | + $backtrace = array_slice($backtrace, 2); |
|
| 47 | + $this->displayDeveloperOutput( |
|
| 48 | + $errno, |
|
| 49 | + $errstr, |
|
| 50 | + $errfile, |
|
| 51 | + $errline, |
|
| 52 | + $backtrace |
|
| 53 | + ); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * handle PHP errors which can't be caught by error-handler |
|
| 58 | + */ |
|
| 59 | + public function handleShutdown() { |
|
| 60 | + $error = error_get_last(); |
|
| 61 | + if ($error === null) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + $this->displayDeveloperOutput( |
|
| 65 | + $error['type'], |
|
| 66 | + $error['message'], |
|
| 67 | + $error['file'], |
|
| 68 | + $error['line'] |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * handle all exceptions |
|
| 74 | + * |
|
| 75 | + * @param \Exception $exception |
|
| 76 | + * |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + public function handleException(\Exception $exception) { |
|
| 80 | + $this->displayDeveloperOutput( |
|
| 81 | + $exception->getCode(), |
|
| 82 | + $exception->getMessage(), |
|
| 83 | + $exception->getFile(), |
|
| 84 | + $exception->getLine(), |
|
| 85 | + null, |
|
| 86 | + $exception |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * show a nice looking and human readable developer output |
|
| 92 | + * |
|
| 93 | + * @param $code |
|
| 94 | + * @param $message |
|
| 95 | + * @param $file |
|
| 96 | + * @param $line |
|
| 97 | + * @param \Exception $exception |
|
| 98 | + */ |
|
| 99 | + protected function displayDeveloperOutput($code, $message, $file, $line, array $backtrace = null, \Exception $exception = null) { |
|
| 100 | + header('HTTP/1.1 500 Internal Server Error'); |
|
| 101 | + $fragment = $this->receiveCodeFragment($file, |
|
| 102 | + $line, 5, 5); |
|
| 103 | + $marker = [ |
|
| 104 | + 'base_url' => $this->settings['base_url'], |
|
| 105 | + 'type' => $exception ? 'Exception' : 'Error', |
|
| 106 | + 'exception_message' => htmlspecialchars($message), |
|
| 107 | + 'exception_code' => htmlspecialchars($code), |
|
| 108 | + 'exception_file' => htmlspecialchars($file), |
|
| 109 | + 'exception_line' => htmlspecialchars($line), |
|
| 110 | + 'exception_fragment' => $fragment, |
|
| 111 | + 'exception_class' => '', |
|
| 112 | + 'wiki_link' => '' |
|
| 113 | + ]; |
|
| 114 | + |
|
| 115 | + if ($exception) { |
|
| 116 | + $marker['exception_class'] = $this->linkClass(get_class($exception)); |
|
| 117 | + $marker['wiki_link'] = ($code > 0) ? '(<a href="https://github.com/PhileCMS/Phile/wiki/Exception_' . $code . '" target="_blank">Exception-Wiki</a>)' : ''; |
|
| 118 | + $backtrace = $exception->getTrace(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($backtrace) { |
|
| 122 | + $marker['exception_backtrace'] = $this->createBacktrace($backtrace); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $DS = DIRECTORY_SEPARATOR; |
|
| 126 | + $pluginPath = realpath(dirname(__FILE__) . $DS . '..') . $DS; |
|
| 127 | + $tplPath = $pluginPath . 'template.php'; |
|
| 128 | + |
|
| 129 | + ob_start(); |
|
| 130 | + extract($marker); |
|
| 131 | + include $tplPath; |
|
| 132 | + ob_end_flush(); |
|
| 133 | + die(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * creates a human readable backtrace |
|
| 138 | + * |
|
| 139 | + * @param array $traces |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + protected function createBacktrace(array $traces) { |
|
| 143 | + if (!count($traces)) { |
|
| 144 | + return ''; |
|
| 145 | + } |
|
| 146 | + $backtraceCodes = []; |
|
| 147 | + |
|
| 148 | + foreach ($traces as $index => $step) { |
|
| 149 | + $backtrace = $this->tag('span', count($traces) - $index, ['class' => 'index']); |
|
| 150 | + $backtrace .= ' '; |
|
| 151 | + |
|
| 152 | + if (isset($step['class'])) { |
|
| 153 | + $class = $this->linkClass($step['class']) . '<span class="divider">::</span>'; |
|
| 154 | + $backtrace .= $class . $this->linkClass($step['class'], $step['function']); |
|
| 155 | + } elseif (isset($step['function'])) { |
|
| 156 | + $backtrace .= $this->tag('span', $step['function'], ['class' => 'function']); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $arguments = $this->getBacktraceStepArguments($step); |
|
| 160 | + if ($arguments) { |
|
| 161 | + $backtrace .= $this->tag('span', "($arguments)", ['class' => 'funcArguments']); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if (isset($step['file'])) { |
|
| 165 | + $backtrace .= $this->receiveCodeFragment($step['file'], $step['line'], 3, 3); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $backtraceCodes[] = $this->tag('pre', $backtrace, ['class' => 'entry']); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return implode('', $backtraceCodes); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * render arguments for backtrace step |
|
| 177 | + * |
|
| 178 | + * @param $step |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + protected function getBacktraceStepArguments($step) { |
|
| 182 | + if (empty($step['args'])) { |
|
| 183 | + return ''; |
|
| 184 | + } |
|
| 185 | + $arguments = ''; |
|
| 186 | + foreach ($step['args'] as $argument) { |
|
| 187 | + $arguments .= strlen($arguments) === 0 ? '' : $this->tag('span', ', ', ['class' => 'separator']); |
|
| 188 | + if (is_object($argument)) { |
|
| 189 | + $class = 'class'; |
|
| 190 | + $content = $this->linkClass(get_class($argument)); |
|
| 191 | + } else { |
|
| 192 | + $class = 'others'; |
|
| 193 | + $content = gettype($argument); |
|
| 194 | + } |
|
| 195 | + $arguments .= $this->tag( |
|
| 196 | + 'span', |
|
| 197 | + $content, |
|
| 198 | + [ |
|
| 199 | + 'class' => $class, |
|
| 200 | + 'title' => print_r($argument, true) |
|
| 201 | + ] |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + return $arguments; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * receive a code fragment from file |
|
| 209 | + * |
|
| 210 | + * @param $filename |
|
| 211 | + * @param $lineNumber |
|
| 212 | + * @param $linesBefore |
|
| 213 | + * @param $linesAfter |
|
| 214 | + * |
|
| 215 | + * @return string |
|
| 216 | + */ |
|
| 217 | + protected function receiveCodeFragment($filename, $lineNumber, $linesBefore = 3, $linesAfter = 3) { |
|
| 218 | + if (!file_exists($filename)) { |
|
| 219 | + return ''; |
|
| 220 | + } |
|
| 221 | + $html = $this->tag('span', $filename . ':<br/>', ['class' => 'filename']); |
|
| 222 | + |
|
| 223 | + $code = file_get_contents($filename); |
|
| 224 | + $lines = explode("\n", $code); |
|
| 225 | + |
|
| 226 | + $firstLine = $lineNumber - $linesBefore - 1; |
|
| 227 | + if ($firstLine < 0) { |
|
| 228 | + $firstLine = 0; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $lastLine = $lineNumber + $linesAfter; |
|
| 232 | + if ($lastLine > count($lines)) { |
|
| 233 | + $lastLine = count($lines); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $line = $firstLine; |
|
| 237 | + $fragment = ''; |
|
| 238 | + while ($line < $lastLine) { |
|
| 239 | + $line++; |
|
| 240 | + |
|
| 241 | + $lineText = htmlspecialchars($lines[$line - 1]); |
|
| 242 | + $lineText = str_replace("\t", ' ', $lineText); |
|
| 243 | + $tmp = sprintf('%05d: %s <br/>', $line, $lineText); |
|
| 244 | + |
|
| 245 | + $class = 'row'; |
|
| 246 | + if ($line === $lineNumber) { |
|
| 247 | + $class .= ' currentRow'; |
|
| 248 | + } |
|
| 249 | + $fragment .= $this->tag('span', $tmp, ['class' => $class]); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + $html .= $fragment; |
|
| 254 | + return $this->tag('pre', $html); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * link the class or method to the API or return the method name |
|
| 259 | + * @param $class |
|
| 260 | + * @param $method |
|
| 261 | + * |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + protected function linkClass($class, $method = null) { |
|
| 265 | + $title = $method ? $method : $class; |
|
| 266 | + if (strpos($class, 'Phile\\') === 0) { |
|
| 267 | + return $title; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $filename = 'docs/classes/' . str_replace('\\', '.', $class) . '.html'; |
|
| 271 | + if (file_exists(Utility::resolveFilePath($filename))) { |
|
| 272 | + return $title; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $href = $this->settings['base_url'] . '/' . $filename; |
|
| 276 | + if ($method) { |
|
| 277 | + $href .= '#method_' . $method; |
|
| 278 | + } |
|
| 279 | + return $this->tag('a', $title, ['href' => $href, 'target' => '_blank']); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * create HTML-tag |
|
| 284 | + * |
|
| 285 | + * @param string $tag |
|
| 286 | + * @param string $content |
|
| 287 | + * @param array $attributes |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + protected function tag($tag, $content = '', array $attributes = []) { |
|
| 291 | + $html = '<' . $tag; |
|
| 292 | + foreach ($attributes as $key => $value) { |
|
| 293 | + $html .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; |
|
| 294 | + } |
|
| 295 | + $html .= '>' . $content . '</' . $tag . '>'; |
|
| 296 | + return $html; |
|
| 297 | + } |
|
| 298 | 298 | } |
@@ -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 |