/** * SetUp */ protected function setUp() { $this->path1 = Proxy\Config::getData('temp', 'image1'); $this->path2 = Proxy\Config::getData('temp', 'image2'); $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['CONTENT_LENGTH'] = 0; }
/** * Init instance * * @return Instance|Nil */ protected static function initInstance() { if (Config::getData('logger')) { return new Instance(); } else { return new Nil(); } }
/** * get CLI Response * * @return Cli\Response */ public function initResponse() { $response = new Cli\Response(); if ($config = Config::getData('response')) { $response->setOptions($config); } Response::setInstance($response); }
/** * Init instance * * @return Instance */ protected static function initInstance() { $instance = new Instance(); if ($data = Config::getData('registry')) { $instance->setFromArray($data); } return $instance; }
/** * Init instance * * @return Instance */ protected static function initInstance() { $config = Config::getData('cache'); if (!$config || !isset($config['enabled']) || !$config['enabled']) { return new Nil(); } else { $instance = new Instance(); $instance->setOptions($config); return $instance; } }
/** * Process * * @param array $settings * @return \Bluz\Grid\Data */ public function process(array $settings = []) { // process filters $where = []; if (!empty($settings['filters'])) { foreach ($settings['filters'] as $column => $filters) { foreach ($filters as $filter => $value) { if ($filter == Grid\Grid::FILTER_LIKE) { $value = '%' . $value . '%'; } $where[] = $column . ' ' . $this->filters[$filter] . ' ' . Proxy\Db::quote($value); } } } // process orders $orders = []; if (!empty($settings['orders'])) { // Obtain a list of columns foreach ($settings['orders'] as $column => $order) { $column = Proxy\Db::quoteIdentifier($column); $orders[] = $column . ' ' . $order; } } // process pages $limit = ' LIMIT ' . ($settings['page'] - 1) * $settings['limit'] . ', ' . $settings['limit']; // prepare query $connect = Proxy\Config::getData('db', 'connect'); if (strtolower($connect['type']) == 'mysql') { // MySQL $dataSql = preg_replace('/SELECT\\s(.*?)\\sFROM/is', 'SELECT SQL_CALC_FOUND_ROWS $1 FROM', $this->source, 1); $countSql = 'SELECT FOUND_ROWS()'; } else { // other $dataSql = $this->source; $countSql = preg_replace('/SELECT\\s(.*?)\\sFROM/is', 'SELECT COUNT(*) FROM', $this->source, 1); if (sizeof($where)) { $countSql .= ' WHERE ' . join(' AND ', $where); } } if (sizeof($where)) { $dataSql .= ' WHERE ' . join(' AND ', $where); } if (sizeof($orders)) { $dataSql .= ' ORDER BY ' . join(', ', $orders); } $dataSql .= $limit; // run queries $data = Proxy\Db::fetchAll($dataSql); $total = Proxy\Db::fetchOne($countSql); $gridData = new Grid\Data($data); $gridData->setTotal($total); return $gridData; }
/** * Test upload file */ public function testUploadFile() { // get path from config $path = Config::getData('temp', 'path'); if (empty($path)) { throw new Exception('Temporary path is not configured'); } $_FILES = array('file' => array('name' => 'test.jpg', 'size' => filesize($path), 'type' => 'image/jpeg', 'tmp_name' => $path, 'error' => 0)); Request::setFileUpload(new TestFileUpload()); $this->dispatchUri('media/crud', ['title' => 'test', 'file' => $_FILES['file']], 'POST'); $this->assertQueryCount('input[name="title"]', 1); $this->assertOk(); }
/** * Process * * @param array $settings * @return \Bluz\Grid\Data */ public function process(array $settings = []) { // process filters if (!empty($settings['filters'])) { foreach ($settings['filters'] as $column => $filters) { foreach ($filters as $filter => $value) { if ($filter == Grid\Grid::FILTER_LIKE) { $value = '%' . $value . '%'; } $this->source->andWhere($column . ' ' . $this->filters[$filter] . ' ?', $value); } } } // process orders if (!empty($settings['orders'])) { // Obtain a list of columns foreach ($settings['orders'] as $column => $order) { $this->source->addOrderBy($column, $order); } } // process pages $this->source->setLimit($settings['limit']); $this->source->setPage($settings['page']); // prepare query $connect = Proxy\Config::getData('db', 'connect'); if (strtolower($connect['type']) == 'mysql') { // MySQL $select = $this->source->getQueryPart('select'); $this->source->select('SQL_CALC_FOUND_ROWS ' . current($select)); // run queries $data = $this->source->execute(); $total = Proxy\Db::fetchOne('SELECT FOUND_ROWS()'); } else { // other $totalSource = clone $this->source; $totalSource->select('COUNT(*)'); // run queries $data = $this->source->execute(); $total = $totalSource->execute(); } $gridData = new Grid\Data($data); $gridData->setTotal($total); return $gridData; }
/** * prepareRequest * * @param string $uri in format "module/controllers" * @param array $params of request * @param string $method HTTP * @param bool $ajax * @return Http\Request */ private function prepareRequest($uri, array $params = null, $method = Http\Request::METHOD_GET, $ajax = false) { Request::setRequestUri($uri); Request::setOptions(Config::getData('request')); Request::setMethod($method); // process $_GET params if ($query = stristr($uri, '?')) { $query = substr($query, 1); // remove `?` sign parse_str($query, $_GET); // fill $_GET } // process custom params if ($params) { Request::setParams($params); } if ($ajax) { $_SERVER['HTTP_ACCEPT'] = 'application/json'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; } else { $_SERVER['HTTP_ACCEPT'] = 'text/html'; } }
/** * Init instance * * @return Instance */ protected static function initInstance() { $instance = new Instance(); $instance->setOptions(Config::getData('session')); return $instance; }
/** * Initial Response instance * @return void */ protected function initResponse() { $response = new Http\Response(); $response->setOptions(Config::getData('response')); Response::setInstance($response); }
/** * SetUp */ protected function setUp() { $this->path = Proxy\Config::getData('temp', 'image1'); $file = array('name' => 'test.jpeg', 'size' => filesize($this->path), 'type' => 'image/jpeg', 'tmp_name' => $this->path, 'error' => 0); $this->httpFile = new File($file); }
/** * setUp */ public function setUp() { $this->db = new Db\Db(); $this->db->setOptions(Proxy\Config::getData('db')); }
/** * Test Registry configuration setup */ public function testRegistry() { $this->assertEquals(["moo" => "baz"], Proxy\Config::getData("registry")); $this->assertEquals("baz", Proxy\Config::getData("registry", "moo")); $this->assertEquals("baz", Proxy\Registry::get('moo')); }
/** * @return array */ public function getAvailableProviders() { return array_keys(Config::getData('hybridauth')['providers']); }
/** * Initial Router instance * * @return void */ protected function initRouter() { $router = new \Bluz\Router\Router(); $router->setOptions(Config::getData('router')); Router::setInstance($router); }