/** * @expectedException Kpacha\Suricate\SuricateException */ public function testSuricateExceptionIsThrowedIdSomethingGoesWrong() { $request = $this->getMock('Request', array('send')); $request->expects($this->once())->method('send')->will($this->throwException(new \Exception('master caution!'))); $client = $this->getMock(self::CLIENT_CLASS); $client->expects($this->once())->method('get')->will($this->returnValue($request)); $suricate = new Suricate($client); $suricate->get('test', 'ca2fff8e-d756-480c-b59e-8297ff886240'); }
public function load($locale = null) { $filename = app_path() . DIRECTORY_SEPARATOR . $this->baseLocaleDir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'language.php'; if (is_readable($filename)) { $this->locale = $locale; $this->translations = (include $filename); } else { Suricate::Logger()->debug(sprintf('Missing translation file for %s', $this->locale)); } }
public static function write($type, $message) { if (in_array($type, static::$types)) { $currentSessionData = Suricate::Session()->read('flash'); if (isset($currentSessionData[$type]) && is_array($currentSessionData[$type])) { $newData = array_merge($currentSessionData[$type], (array) $message); } else { $newData = (array) $message; } $currentSessionData[$type] = $newData; Suricate::Session()->write('flash', $currentSessionData); } }
protected function init() { if (static::$container === null) { switch ($this->type) { case 'memcache': static::$container = Suricate::CacheMemcache(true); break; case 'apc': static::$container = Suricate::CacheApc(true); break; default: throw new \Exception("Unknown cache type " . $this->type); break; } } }
public function save() { $db_handler = Suricate::Database(true); if ($this->parent_id != '') { // 1st step : delete all records for current parent_id $sql = "DELETE FROM `" . static::SQL_RELATION_TABLE_NAME . "`"; $sql .= " WHERE"; $sql .= " " . static::PARENT_ID_NAME . "=:parent_id"; $sqlParams = array(); $sqlParams['parent_id'] = $this->parent_id; //echo "--> delete old items with : $sql<br/>"; $db_handler->query($sql, $sqlParams); // 2nd step : create items that are not saved in db foreach ($this->items as &$current_item) { if ($current_item->{$current_item::TABLE_INDEX} == '') { // 2nd step : create items that are not saved in db //echo "Item missing id, saving id<br/>"; /*foreach ($this->additionalMappingFieldList as $additionalField) { $current_item->$additionalField }*/ $current_item->save(); } //3rd step : create the mapping $sqlParams = array(); $sql = "INSERT INTO `" . static::SQL_RELATION_TABLE_NAME . "`"; $sql .= " (`" . static::PARENT_ID_NAME . "`, `" . static::MAPPING_ID_NAME . "`"; if (count($this->additionalMappingFieldList)) { $sql .= ', ' . implode(",", array_map(function ($s) { return '`' . $s . '`'; }, $this->additionalMappingFieldList)); } $sql .= ")"; $sql .= " VALUES"; $sql .= "(:parent_id, :id"; if (count($this->additionalMappingFieldList)) { foreach ($this->additionalMappingFieldList as $additionalField) { $sql .= ',:' . $additionalField; $sqlParams[$additionalField] = $current_item->{$additionalField}; } } $sql .= ")"; $sqlParams['parent_id'] = $this->parent_id; $sqlParams['id'] = $current_item->id; $db_handler->query($sql, $sqlParams); } } }
public function save() { // 1st step : delete all records for current parentId $sql = "DELETE FROM `" . static::TABLE_NAME . "`"; if (static::PARENT_ID_NAME != '') { $sql .= " WHERE"; $sql .= " " . static::PARENT_ID_NAME . "=:parent_id"; $sqlParams = array('parent_id' => $this->parentId); } else { $sqlParams = array(); } Suricate::Database()->query($sql, $sqlParams); // 2nd step : save all current items foreach ($this->items as $currentItem) { $currentItem->save(true); // Force insert } }
protected function connectDB() { if (!$this->dbLink) { $this->dbLink = Suricate::Database(); if (static::DB_CONFIG != '') { $this->dbLink->setConfig(static::DB_CONFIG); } } }
/** * Loop through each defined routes, to find good one * @return null */ public function doRouting() { $hasRoute = false; foreach ($this->routes as $route) { if ($route->isMatched) { $hasRoute = true; Suricate::Logger()->debug('Route "' . $route->getPath() . '" matched, target: ' . json_encode($route->target)); $result = $route->dispatch($this->response, $this->appMiddlewares); if ($result === false) { break; } } } // No route matched if (!$hasRoute) { Suricate::Logger()->debug('No route found'); app()->abort('404'); } $this->response->write(); }