public function process(callable $callBack = null) { if (empty($this[MY_PARENT])) { \PMVC\l(__DIR__ . '/src/Monitor.php'); new Monitor($callBack); } }
/** * @see http://www.phpconcept.net/pclzip/user-guide/18 */ public function open($zip_file) { if (!class_exists('PclZip')) { \PMVC\l(__DIR__ . '/src/pclzip.lib.php'); } $zip = new \PclZip($zip_file); $this['current'] = $zip; return $zip; }
public function initProvider($providerName, $config) { $className = ucfirst($providerName) . 'Provider'; if (!class_exists(__NAMESPACE__ . '\\' . $className)) { $this->loadClass('Logger'); $this->loadClass('ProviderModel'); $file = __DIR__ . '/src/providers/' . $className . '.php'; \PMVC\l($file); } $class = __NAMESPACE__ . '\\' . $className; return new $class($providerName, $config, $this['storage']); }
public function getDb($key) { $path = \PMVC\lastSlash($this['dbs']) . $key . '.php'; if (\PMVC\realpath($path)) { \PMVC\l($path); $class = __NAMESPACE__ . '\\' . $key; if (class_exists($class)) { return new $class(); } else { trigger_error($class . ' not exists.'); } } else { trigger_error($path . ' not exists.'); } }
/** * @param int $id group guid * @param string $key group key */ public function getDb($id, $key = null) { if (!$this->_connected) { return !trigger_error('Server is not connected.'); } if (empty($this->dbs[$id])) { $path = $this->getDir() . '/src/dbs/' . $key . '.php'; if (\PMVC\realpath($path)) { \PMVC\l($path); $nameSpace = $this->getNameSpace(); $class = $nameSpace . '\\dbs\\' . $key; if (class_exists($class)) { $this->dbs[$id] = new $class($this['this'], $id); } else { return !trigger_error($class . ' not exists.'); } } else { $baseDb = $this->getBaseDb(); $this->dbs[$id] = new $baseDb($this['this'], $id); } } return $this->dbs[$id]; }
<?php namespace PMVC\PlugIn\get; \PMVC\l(__DIR__ . '/src/GetInterface.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\get'; function get($k) { return \PMVC\plug('get')->get($k); } class get extends \PMVC\PlugIn { public function get($k) { $option =& \PMVC\getOption($k); if (!is_null($option)) { return $option; } else { if (is_array($this['order'])) { foreach ($this['order'] as $get) { $plug = \PMVC\plug($get); if ($plug && $plug->has($k)) { return $plug->get($k); } } } } return $option; } }
<?php namespace PMVC\PlugIn\url; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\url'; \PMVC\l(__DIR__ . '/src/UrlObject.php'); \PMVC\initPlugIn(['getenv' => null]); class url extends \PMVC\PlugIn { /** * Keep value to check now use http or https * @var string */ private $protocol = null; /** * Set env */ public function setEnv(array $arr, $overwrite = true) { $env = \PMVC\plug('getenv'); foreach ($arr as $key) { if ($overwrite || !isset($this[$key])) { $this[$key] = $env->get($key); } } } /** * Get Url */ function getUrl($url) {
<?php namespace PMVC\PlugIn\annotation; \PMVC\l(__DIR__ . '/src/AnnotationReader.php'); \PMVC\l(__DIR__ . '/src/AnnotationParser.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\annotation'; class annotation extends \PMVC\PlugIn { public function get($s) { $doc = $this->getRawAnnotation($s); if (is_null($doc)) { return !trigger_error('Can\'t find annotation. ' . print_r($s, true)); } $parser = new AnnotationParser($doc); return $parser; } public function getRawAnnotation($s) { $reader = new AnnotationReader(); if (is_string($s)) { if (class_exists($s)) { return $reader->getClass($s); } elseif (function_exists($s)) { return $reader->getFunction($s); } } elseif (is_array($s) && is_callable($s)) { if (method_exists($s[0], $s[1])) { return $reader->getMethod($s[0], $s[1]); } elseif (is_callable([$s[0], 'isCallable'])) {
<?php namespace PMVC\PlugIn\latlon; \PMVC\l(__DIR__ . '/src/MercatorProjection.php'); \PMVC\l(__DIR__ . '/src/GeoPoint.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\latlon'; class latlon extends \PMVC\PlugIn { private $_mercator; public function init() { $mp = new MercatorProjection(); $this->setDefaultAlias($mp); } public function getLatLon($lat, $lon) { return new GeoPoint($lat, $lon); } }
public function init() { \PMVC\l(__DIR__ . '/src/FlickrApi.php'); $flickr = new FlickrApi($this['appId'], $this['appSecret'], $this['callBack']); $this->setDefaultAlias($flickr); }
<?php namespace PMVC\PlugIn\debug; use PMVC as p; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\debug'; \PMVC\l(__DIR__ . '/src/DebugDumpInterface.php'); const INPUT_FIELD = '_trace'; /** * @parameters string output Debug output function [debug_console|debug_store|debug_cli] * @parameters string truncate Debug truncate dump function parameter string lengths * @parameters numeric level Debug dump level */ class debug extends p\PlugIn { private $run = false; private $_output; public function init() { if (empty($this['output'])) { $this['output'] = 'debug_console'; } if (empty($this['truncate'])) { $this['truncate'] = 100; } p\callPlugin('dispatcher', 'attach', [$this, 'SetConfig__run_form_']); $this->setLevelType(\PMVC\value($_REQUEST, [INPUT_FIELD]), false); } public function getLevel($level, $default = 1) { $levels = ['trace' => 1, 'debug' => 2, 'info' => 3, 'warn' => 4, 'error' => 5];
<?php namespace PMVC\PlugIn\file_info; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\file_info'; \PMVC\l(__DIR__ . '/src/FilePath.php'); \PMVC\l(__DIR__ . '/src/File.php'); class file_info extends \PMVC\PlugIn { function path($path) { return new FilePath($path); } function file($path) { return new File($path); } }
<?php namespace PMVC\PlugIn\rethinkdb; use r; \PMVC\l(__DIR__ . '/src/BaseRethinkDB.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\rethinkdb'; class rethinkdb extends \PMVC\PlugIn { private $conn; use \IdOfThings\GetDb; public function init() { if (!$this->conn) { $get = \PMVC\plug('get'); $host = $get->get('RETHINKDB_HOST'); if (!$host) { return; } $this->conn = r\connect($host, $get->get('RETHINKDB_PORT')); } var_dump($this->conn); $this['baseDb'] = __NAMESPACE__ . '\\BaseRethinkDB'; } }
<?php namespace PMVC\PlugIn\dispatcher; use PMVC as p; use PMVC\Event; use SplObserver; ${_INIT_CONFIG}[_CLASS] = 'PMVC\\PlugIn\\dispatcher\\dispatcher'; \PMVC\l(__DIR__ . '/src/Subject.php'); /** * Const */ const PREP = '_prep'; const POST = '_post'; /** * Base Observerable class */ class dispatcher extends p\PlugIn { /** * Last config key. */ private $_lastConfigKey; /** * Private * $observers an array of Observer objects to notify */ private $_subjects = []; /** * Notify will call all observer update() function * @return void
<?php namespace PMVC\PlugIn\pagination; use LogicException; use ArrayAccess; \PMVC\l(__DIR__ . '/src/page.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\pagination'; const BEGIN = '0'; const END = '1'; const PRE_PAGE_NUM = 'perPageNum'; const TOTAL = 'total'; const TOTAL_PAGE = 'totalPage'; const CURRENT_PAGE = 'currentPage'; const BACKWARD = 'backward'; const FORWARD = 'forward'; const LAST_PAGE = 'lastPage'; const FIRST_PAGE = 'firstPage'; const TYPE = 'type'; #url const URL = 'url'; const QUERY_B = 'b'; const QUERY_PAGE = 'page'; /** * @parameters int PRE_PAGE_NUM * @parameters int TOTAL * @parameters int CURRENT_PAGE * @parameters int BEGIN */ class pagination extends \PMVC\PlugIn {
<?php namespace PMVC\PlugIn\file_info; \PMVC\l(__DIR__ . '/FileSize.php'); \PMVC\l(__DIR__ . '/FileTime.php'); class File extends FilePath { function __construct($path) { $realPath = \PMVC\realPath($path); if (!$realPath) { return !trigger_error('File not exists. [' . $path . ']'); } else { parent::__construct($realPath); } } function realPath() { return $this->_path; } function getSize() { return new FileSize($this->_path); } function getTime() { return new FileTime($this->_path); } }
<?php namespace PMVC\PlugIn\filter; use PMVC\Object; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\filter'; \PMVC\l(__DIR__ . '/src/BaseFilter.php'); /** * @parameters string lastError debug message */ class filter extends \PMVC\PlugIn { public function one($type, array $params = []) { $value = $params[0] instanceof Object ? $params[0] : new Object($params[0]); array_shift($params); return call_user_func([$this, 'to_' . $type], $value, $params); } public function all(array $values, array $params) { $results = array(); foreach ($values as $key => $value) { $type = array_shift($params[$key]); array_unshift($params[$key], $value); $results[$key] = $this->one($type, $params[$key]); } return $results; } }
<?php namespace PMVC\PlugIn\file_list; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\download'; \PMVC\l(__DIR__ . '/_dump.php'); class download extends dump { function processHeader($filenamem, $newName) { $info = \PMVC\plug('file_info')->file($filenamem); $contentType = $info->getContentType(); $size = $info->getSize()->size; if (is_null($newName)) { $newName = $info->pathinfo['basename']; } header('Content-Description: File Transfer'); header('Content-Type: ' . $contentType); header('Content-Disposition: attachment; filename="' . $newName . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . $size); } }
<?php namespace PMVC\PlugIn\cache_header; \PMVC\l(__DIR__ . '/src/CacheHeaderHelper.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\cache_header'; class cache_header extends \PMVC\PlugIn { function init() { $this->setDefaultAlias(new CacheHeaderHelper()); if (!empty($this[0]) || strlen($this[0])) { \PMVC\callPlugin(\PMVC\getOption(_ROUTER), 'processHeader', [call_user_func_array([$this, 'getCacheHeader'], $this[0])]); } } }
<?php namespace PMVC\PlugIn\algolia; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\algolia'; \PMVC\initPlugin(['guid' => null]); \PMVC\l(__DIR__ . '/src/BaseAlgolia.php'); /** * @parameters string app * @parameters string key */ class algolia extends \IdOfThings\GetDb { public function init() { if (!isset($this['app'])) { $this['app'] = \PMVC\getOption('ALGOLIA_APP'); } if (!isset($this['key'])) { $this['key'] = \PMVC\getOption('ALGOLIA_KEY'); } } public function getBaseDb() { return __NAMESPACE__ . '\\BaseAlgolia'; } public function getNameSpace() { return __NAMESPACE__; } public function getBaseUrl()
<?php namespace PMVC\PlugIn\session; use PMVC\PlugIn; use SessionHandlerInterface; \PMVC\l(__DIR__ . '/src/BaseSession.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\session'; class session extends PlugIn { public function init() { if (empty($this['api'])) { $api = \PMVC\plug('url')->realUrl(); $api = str_replace('index.php', 'api.php', $api); $this['api'] = $api . '/session/'; } session_set_save_handler($this->curl(), true); if (empty($this['disable_start'])) { session_start(); } } }
<?php namespace PMVC\PlugIn\otp; \PMVC\l(__DIR__ . '/GoogleAuthenticator/PHPGangsta/GoogleAuthenticator.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\otp'; class otp extends \PMVC\PlugIn { public function init() { $googleAuth = new \PHPGangsta_GoogleAuthenticator(); $this->setDefaultAlias($googleAuth); } public function getNewSecret($name) { $return = new \stdClass(); $return->secret = $this->createSecret(); $return->qrcode = $this->getQRCodeGoogleUrl($name, $return->secret); $this['secret'] = $return->secret; return $return; } public function getOneCode($params = array()) { return $this->getCode($this['secret']); } public function validate($params = array()) { \PMVC\set($this, $params); return $this->verifyCode($this['secret'], $this['one']); } }
<?php namespace PMVC\PlugIn\benchmark; \PMVC\l(__DIR__ . '/src/class.wristwatch.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\benchmark'; class benchmark extends \PMVC\PlugIn { public function init() { $this->setDefaultAlias(new wristwatch()); \PMVC\plug('dispatcher')->attach($this, \PMVC\Event\FINISH); \PMVC\plug('dispatcher')->attach($this, \PMVC\Event\B4_PROCESS_VIEW); } public function tag($s = null) { $this->SetFlag($s); } public function onB4ProcessView() { $this->tag('b4 process view'); } public function onFinish() { $this->ReadFlags(); } }
<?php namespace PMVC\PlugIn\cli; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\cli'; \PMVC\l(__DIR__ . '/src/Color2.php'); \PMVC\initPlugIn(['controller' => null]); const PLUGIN = 'cli'; class cli extends \PMVC\PlugIn implements \PMVC\RouterInterface { private $_color; public function onMapRequest() { $controller = \PMVC\plug('controller'); $opts = $this->getopt(); $request = $controller->getRequest(); foreach ($opts as $k => $v) { if (!is_numeric($k)) { $request[$k] = $v; } elseif ($k > 1) { $request[] = $v; } } if (empty($opts[1])) { return; } else { $app = explode(':', $opts[1]); } if (isset($app[0])) { $controller->setApp($app[0]); }
public function getPalette($file) { \PMVC\l(__DIR__ . '/src/ColorPalette.php'); $image = new ImageFile($file); return ColorPalette::GenerateFromLocalImage($image); }
<?php namespace PMVC\PlugIn\curl; \PMVC\l(__DIR__ . '/src/CurlInterface.php'); \PMVC\l(__DIR__ . '/src/CurlHelper.php'); \PMVC\l(__DIR__ . '/src/CurlResponder.php'); \PMVC\l(__DIR__ . '/src/MultiCurlHelper.php'); ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\curl'; class curl extends \PMVC\PlugIn { public function init() { $this->setDefaultAlias(new MultiCurlHelper()); } private function _add($url, $function, $opts) { if (!empty($this['session'])) { $oCurl = $this['session']; unset($this['session']); } else { $oCurl = new CurlHelper(); } $oCurl->setOptions($url, $function, $opts); $this->add($oCurl); return $oCurl; } public function get($url = null, $function = null) { return $this->_add($url, $function, array()); }
<?php namespace PMVC\PlugIn\ssdb; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\ssdb'; \PMVC\l(__DIR__ . '/lib/SSDB.php'); \PMVC\l(__DIR__ . '/src/BaseSsdb.php'); \PMVC\l(__DIR__ . '/src/BaseZset.php'); \PMVC\l(__DIR__ . '/src/BaseTempSsdb.php'); class ssdb extends \IdOfThings\GetDb { public function init() { if (empty($this['ssdb'])) { $get = \PMVC\plug('get'); $host = $get->get('SSDB_HOST'); if (empty($host)) { return; } try { $ssdb = new \SimpleSSDB($host, $get->get('SSDB_PORT')); $this['ssdb'] = $ssdb; $this->setDefaultAlias($this['ssdb']); $this->setConnected(true); } catch (Exception $e) { \PMVC\log($e->getMessage()); \PMVC\d($e->getMessage()); } } } public function getBaseDb()
public function init() { \PMVC\l(__DIR__ . '/src/XLSXWriter.php'); }
<?php namespace PMVC\PlugIn\file_list; ${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\\file_list'; \PMVC\l(__DIR__ . '/src/FileList.php'); class file_list extends \PMVC\PlugIn { private $olist; function init() { $this->olist = new FileList(); } function ls(...$p) { if ($this['hash']) { $this->olist->setChecksum($this['hash']); } if ($this['exclude']) { $excludes = \PMVC\splitDir($this['exclude']); foreach ($excludes as $exclude) { $this->olist->addExclude($exclude); } } if ($this['maskKey']) { $this->olist->maskKey($this['maskKey']); } if ($this['debug']) { $this->olist->debug = $this['debug']; } if ($this['callBack']) {