/** * Get the root object behind the facade. * * @return mixed */ public static function getFacadeInstance() { $className = get_called_class(); if (!isset(static::$_instances[$className])) { static::$_instances[$className] = Di::getDefault()->getShared(static::getFacadeName()); } return static::$_instances[$className]; }
/** * @param string $name * * @return bool */ public function __isset($name) { if ($name === 'di' || $name === 'persistent') { return true; } if ($this->_dependencyInjector === null) { $this->_dependencyInjector = Di::getDefault(); } return $this->_dependencyInjector->has($name); }
/** * Generate a SQL SELECT statement for an aggregate * * @param string $function * @param string $alias * @param string $column * @param string|array $parameters * @param int|array $cacheOptions * * @return mixed * @throws \ManaPHP\Mvc\Model\Exception */ protected static function _groupResult($function, $alias, $column, $parameters, $cacheOptions) { $dependencyInjector = Di::getDefault(); $modelsManager = $dependencyInjector->getShared('modelsManager'); if ($parameters === null) { $parameters = []; } elseif (is_string($parameters)) { $parameters = [$parameters]; } if (preg_match('#^[a-z_][a-z0-9_]*$#i', $column) === 1) { $column = '[' . $column . ']'; } if (isset($parameters['group'])) { $columns = "[{$parameters['group']}], {$function}({$column}) AS [{$alias}]"; } else { $columns = "{$function}({$column}) AS [{$alias}]"; } /** * @var $modelsManager \ManaPHP\Mvc\Model\Manager */ $builder = $modelsManager->createBuilder($parameters)->columns($columns)->from(get_called_class()); $resultset = $builder->execute($cacheOptions); if (isset($parameters['group'])) { return $resultset; } return $resultset[0][$alias]; }
/** * \ManaPHP\Di\FactoryDefault constructor */ public function __construct() { parent::__construct(); $this->_services = ['eventsManager' => 'ManaPHP\\Event\\Manager', 'alias' => 'ManaPHP\\Alias', 'configure' => 'ManaPHP\\Configure', 'router' => 'ManaPHP\\Mvc\\Router', 'dispatcher' => 'ManaPHP\\Mvc\\Dispatcher', 'url' => 'ManaPHP\\Mvc\\Url', 'modelsManager' => 'ManaPHP\\Mvc\\Model\\Manager', 'modelsMetadata' => 'ManaPHP\\Mvc\\Model\\Metadata\\Adapter\\Memory', 'queryBuilder' => ['ManaPHP\\Mvc\\Model\\QueryBuilder', false], 'response' => 'ManaPHP\\Http\\Response', 'cookies' => 'ManaPHP\\Http\\Cookies', 'request' => 'ManaPHP\\Http\\Request', 'filter' => 'ManaPHP\\Http\\Filter', 'crypt' => 'ManaPHP\\Security\\Crypt', 'flash' => 'ManaPHP\\Mvc\\View\\Flash\\Adapter\\Direct', 'flashSession' => 'ManaPHP\\Mvc\\View\\Flash\\Adapter\\Session', 'session' => ['class' => 'ManaPHP\\Http\\Session', 'parameters' => ['ManaPHP\\Http\\Session\\Adapter\\File']], 'sessionBag' => ['ManaPHP\\Http\\Session\\Bag', false], 'view' => 'ManaPHP\\Mvc\\View', 'logger' => ['class' => 'ManaPHP\\Logger', 'parameters' => ['ManaPHP\\Logger\\Adapter\\File']], 'renderer' => 'ManaPHP\\Renderer', 'debugger' => 'ManaPHP\\Debugger', 'password' => 'ManaPHP\\Authentication\\Password', 'serializer' => 'ManaPHP\\Serializer\\Adapter\\JsonPhp', 'cache' => ['class' => 'ManaPHP\\Cache', 'parameters' => ['ManaPHP\\Cache\\Adapter\\File']], 'store' => ['class' => 'ManaPHP\\Store', 'parameters' => ['ManaPHP\\Store\\Adapter\\File']], 'counter' => ['class' => 'ManaPHP\\Counter', 'parameters' => ['ManaPHP\\Counter\\Adapter\\Db']], 'httpClient' => 'ManaPHP\\Http\\Client', 'captcha' => 'ManaPHP\\Security\\Captcha', 'csrfToken' => 'ManaPHP\\Security\\CsrfToken', 'authorization' => 'ManaPHP\\Authorization\\Bypass', 'userIdentity' => 'ManaPHP\\Authentication\\UserIdentity', 'paginator' => 'ManaPHP\\Paginator', 'filesystem' => 'ManaPHP\\Filesystem\\Adapter\\File', 'random' => 'ManaPHP\\Security\\Random', 'messageQueue' => 'ManaPHP\\Message\\Queue\\Adapter\\Db', 'crossword' => 'ManaPHP\\Text\\Crossword', 'rateLimiter' => 'ManaPHP\\Security\\RateLimiter\\Adapter\\Db', 'linearMeter' => 'ManaPHP\\Meter\\Linear', 'roundMeter' => 'ManaPHP\\Meter\\Round', 'secint' => 'ManaPHP\\Security\\Secint', 'swordCompiler' => 'ManaPHP\\Renderer\\Engine\\Sword\\Compiler', 'tasksMetadata' => ['class' => 'ManaPHP\\Task\\Metadata', 'parameters' => ['ManaPHP\\Task\\Metadata\\Adapter\\Redis']], 'viewsCache' => ['class' => 'ManaPHP\\Cache\\Adapter\\File', 'parameters' => [['dir' => '@data/viewsCache', 'extension' => '.html']]], 'modelsCache' => ['class' => 'ManaPHP\\Cache\\Adapter\\File', 'parameters' => [['dir' => '@data/modelsCache', 'extension' => '.json']]]]; }
/** * Get / set the specified session value. * * If an array is passed as the key, we will assume you want to set an array of values. * * @param array|string $key * @param mixed $default * * @return mixed */ function session($key = null, $default = null) { if ($key === null) { return Di::getDefault()->session; } if (is_array($key)) { $session = Di::getDefault()->session; foreach ($key as $k => $v) { $session->set($k, $v); } } else { return Di::getDefault()->session->get($key, $default); } }