getDefault() public static method

Return the First DI created
public static getDefault ( ) : static
return static
Exemplo n.º 1
0
 /**
  * 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];
 }
Exemplo n.º 2
0
 /**
  * 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];
 }
Exemplo n.º 3
0
 /**
  * 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);
     }
 }