Exemplo n.º 1
0
 public function setUp()
 {
     $config = (include __DIR__ . '/../config.php');
     $this->config = $config;
     $this->di = DI::getDefault();
     $this->loadAnnotations();
 }
 /**
  * Set up the test environment
  * @return void
  */
 public function setUp()
 {
     //$this->controller = new LoginController;
     $this->controller = new LoginController();
     $this->view = new View();
     $this->view->disable();
     $this->di = DI::getDefault();
     parent::setUp();
 }
Exemplo n.º 3
0
 public function __get($var_name)
 {
     $di = DI::getDefault();
     if ($di->hasService($var_name)) {
         return $di->getService($var_name);
     }
     if ($var_name == "di") {
         return $di;
     }
 }
Exemplo n.º 4
0
 /**
  * Tests the methods for getting, setting and clearing the default
  * service provider.
  */
 public function testGetDefaultAndSetDefault()
 {
     DI::clearDefault();
     // guard condition
     $di = DI::getDefault();
     // get a fresh default
     $this->assertInstanceOf('Vectorface\\SnappyRouter\\Di\\Di', $di);
     DI::setDefault($di);
     $this->assertEquals($di, DI::getDefault());
 }
Exemplo n.º 5
0
 /**
  * Set up the test environment
  * @return void
  */
 public function setUp()
 {
     //need to use mock feature to remove contructor and exit functions
     $this->controller = new MockApiController();
     //setup our view if needed
     $this->view = new View();
     $this->di = DI::getDefault();
     //call parent setup if any
     parent::setUp();
 }
Exemplo n.º 6
0
 /**
  * Check if \Phalcon\Di has session service
  *
  * @return bool
  */
 private function hasSession()
 {
     if (DI::getDefault()->has('session') === true) {
         // get instance of session class
         $this->session = DI::getDefault()->getSession();
         if ($this->session->getId() === '') {
             $this->session->start();
         }
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
Arquivo: Logger.php Projeto: rj28/test
 /** @return Logger_File */
 public static function instance($name)
 {
     $serviceName = 'logger_' . strtolower($name);
     $di = DI::getDefault();
     if ($di->has($serviceName)) {
         return $di->getShared($serviceName);
     } else {
         if (!($logFileName = Config::instance()->{$serviceName})) {
             exit("Logger {$name} is not configured");
         }
         if (!file_exists($logFileName) || !is_writable($logFileName)) {
             exit('Log file is does not exists or not writeable ' . $logFileName);
         }
         $logger = static::getLoggerInstance($name, $logFileName);
         $di->set($serviceName, $logger, true);
         return $logger;
     }
 }
Exemplo n.º 8
0
 /**
  * Constructor
  *
  * @param string $cacheName
  * @param string $cacheType
  * @param int $lifeTime
  */
 public function __construct($cacheName = 'GLOBAL', $cacheType = 'ApcCache', $lifeTime = null)
 {
     if ($lifeTime) {
         $this->lifeTime = $lifeTime;
     }
     $this->config = DI::getDefault()->get('config');
     $this->cacheName = $this->config->cachePrefix . $cacheName;
     if ($cacheType == self::memCache && $this->config->memCache->status) {
         $this->_initMemCached();
     } elseif ($cacheType == self::APC_CACHE && $this->config->apcCache->status) {
         $this->_initApcCache();
     } elseif ($cacheType == self::REDIS_CACHE && $this->config->redisCache->status) {
         $this->_initRedisCache();
     } else {
         $this->_initFileCache();
     }
 }
Exemplo n.º 9
0
 /**
  * @return \Phalcon\Security
  */
 public static function getSecurity()
 {
     return DI::getDefault()->get('security');
 }
Exemplo n.º 10
0
Arquivo: Pager.php Projeto: rj28/test
 public static function getDI()
 {
     return static::$_di ?: DI::getDefault();
 }
Exemplo n.º 11
0
 /**
  * Resolves the relations
  *
  * @throws \RuntimeException
  * @return EagerLoad[]
  */
 private function buildTree()
 {
     uksort($this->eagerLoads, 'strcmp');
     $di = DI::getDefault();
     $mM = $di['modelsManager'];
     $eagerLoads = $resolvedRelations = [];
     foreach ($this->eagerLoads as $relationAliases => $queryConstraints) {
         $nestingLevel = 0;
         $relationAliases = explode('.', $relationAliases);
         $nestingLevels = count($relationAliases);
         do {
             do {
                 $alias = $relationAliases[$nestingLevel];
                 $name = join('.', array_slice($relationAliases, 0, $nestingLevel + 1));
             } while (isset($eagerLoads[$name]) && ++$nestingLevel);
             if ($nestingLevel === 0) {
                 $parentClassName = $this->subjectClassName;
             } else {
                 $parentName = join('.', array_slice($relationAliases, 0, $nestingLevel));
                 $parentClassName = $resolvedRelations[$parentName]->getReferencedModel();
                 if ($parentClassName[0] === '\\') {
                     ltrim($parentClassName, '\\');
                 }
             }
             if (!isset($resolvedRelations[$name])) {
                 $mM->load($parentClassName);
                 $relation = $mM->getRelationByAlias($parentClassName, $alias);
                 if (!$relation instanceof Relation) {
                     throw new \RuntimeException(sprintf('There is no defined relation for the model `%s` using alias `%s`', $parentClassName, $alias));
                 }
                 $resolvedRelations[$name] = $relation;
             } else {
                 $relation = $resolvedRelations[$name];
             }
             $relType = $relation->getType();
             if ($relType !== Relation::BELONGS_TO && $relType !== Relation::HAS_ONE && $relType !== Relation::HAS_MANY && $relType !== Relation::HAS_MANY_THROUGH) {
                 throw new \RuntimeException(sprintf('Unknown relation type `%s`', $relType));
             }
             if (is_array($relation->getFields()) || is_array($relation->getReferencedFields())) {
                 throw new \RuntimeException('Relations with composite keys are not supported');
             }
             $parent = $nestingLevel > 0 ? $eagerLoads[$parentName] : $this;
             $constraints = $nestingLevel + 1 === $nestingLevels ? $queryConstraints : null;
             $eagerLoads[$name] = new EagerLoad($relation, $constraints, $parent);
         } while (++$nestingLevel < $nestingLevels);
     }
     return $eagerLoads;
 }
Exemplo n.º 12
0
 /**
  * Get pagination from raw sql
  *
  * @param $rawSQL
  * @param $paginationLimit
  * @param $currentPage
  * @param \Phalcon\Mvc\Model|\stdClass $object
  * @return \stdClass
  */
 public static function getPaginationFromRawSQL($rawSQL, $paginationLimit, $currentPage, $object)
 {
     $result = new \stdClass();
     $result->before = 1;
     $result->first = 1;
     $result->next = 0;
     $result->current = 1;
     $result->total_pages = 0;
     $result->total_items = 0;
     $currentPage = self::checkInt($currentPage);
     $paginationLimit = self::checkInt($paginationLimit);
     /**
      * @var mixed $db
      */
     $db = DI::getDefault()->get('db');
     try {
         $totalSQL = "SELECT count(*) AS total FROM ({$rawSQL}) AS Temp";
         $totalItem = $db->fetchOne($totalSQL, Db::FETCH_NUM);
         if (count($totalItem) >= 0) {
             $totalItem = $totalItem[0];
             if ($totalItem[0] >= 0) {
                 $result = new \stdClass();
                 $totalPage = ceil($totalItem / $paginationLimit);
                 $result->first = 1;
                 $result->current = $currentPage;
                 if ($currentPage < $totalPage) {
                     $result->next = $currentPage + 1;
                 } else {
                     $result->next = $totalPage;
                 }
                 $result->last = $totalPage;
                 $result->total_pages = $totalPage;
                 $result->total_items = $totalItem;
                 $rawSQL = $rawSQL . ' LIMIT ' . $paginationLimit . ' OFFSET ' . ($currentPage - 1) * $paginationLimit;
                 $result->items = new ResultSet(null, $object, $db->query($rawSQL));
                 return $result;
             }
         }
     } catch (\Exception $e) {
         die('SQL Error: ' . $rawSQL);
     }
     return $result;
 }
Exemplo n.º 13
0
 /**
  * Returns an Escaper service from the default DI
  *
  * @return \Scene\EscaperInterface
  * @throws Exception
  */
 public static function getEscaperService()
 {
     $escaper = self::$_escaperService;
     if (!is_object($escaper)) {
         $dependencyInjector = self::$_dependencyInjector;
         if (!is_object($dependencyInjector)) {
             $dependencyInjector = DI::getDefault();
         }
         if (!is_object($dependencyInjector)) {
             throw new Exception('A dependency injector container is required to obtain the "escaper" service');
         }
         $escaper = $dependencyInjector->getShared('escaper');
         self::$_escaperService = $escaper;
     }
     return $escaper;
 }
Exemplo n.º 14
0
 /**
  * Inserts or updates the database table
  */
 public function save()
 {
     $di = DI::getDefault();
     $database = $di->getService("database");
     /**
      * Decide if we should update or insert
      * (if we know the record exists in the database...)
      */
     if ($this->_exists_in_db) {
         /**
          * Retrieve a query from the query builder
          */
         $query = $database->buildQuery($this->_table_name, "update", array("columns" => $this->_columns));
         /**
          * Create an array with the model attributes (binding parameters)
          */
         $attributes = $this->getAttributes();
         /**
          * Add "snap_" prefix to the snapshot in order to not get index conflict when we merge attributes and snapshot
          */
         $snapshot = array();
         foreach ($this->_snapshot as $key => $value) {
             $snapshot["snap_" . $key] = $value;
         }
         /**
          * Merge our binding parameters.
          * Bind the parameters to the query and return the result.
          */
         return $query->execute(array_merge($attributes, $snapshot));
     } else {
         /**
          * Retrieve a query from the query builder
          */
         $query = $database->buildQuery($this->_table_name, "insert", array("columns" => $this->_columns));
         /**
          * Create an array with the model attributes (binding parameters)
          */
         $attributes = $this->getAttributes();
         /**
          * Bind the parameters and return the result
          */
         return $query->execute($attributes);
     }
 }
Exemplo n.º 15
0
 /**
  * Set up test variables
  *
  * @return void
  * @author Dan Cox
  */
 public function setUp()
 {
     $this->di = DI::getDefault();
 }