public function prepare() { if ($this->ready) { return null; } $this->ready = true; if (empty($this->classMethods)) { Exception::raise($this->fullController . ' is empty ', 2); } $controller = $this->controller; $classMethods = $this->classMethods; foreach ($classMethods as $value) { $route = $this->getRoute($value); if ($route) { Route::set($route[0], $route[1], $controller . ':' . $value); } } }
public static function view($type, $view) { if ($view !== null && View::exists($view) === false) { Exception::raise($view . ' view is not found', 2); } $callRender = array('\\Experimental\\Debug', 'render' . ucfirst($type)); switch ($type) { case 'error': self::$views[$type] = $view; App::on('error', $callRender); break; case 'classes': case 'performance': self::$views[$type] = $view; App::on('terminate', $callRender); break; default: Exception::raise($type . ' is not valid event', 2); } self::register(); }
public function prepare() { if ($this->ready) { return null; } $this->ready = true; if (empty($this->classMethods)) { Exception::raise($this->fullController . ' is empty ', 2); } $format = $this->format; $controller = $this->controller; $classMethods = $this->classMethods; foreach ($classMethods as $value) { if ($value[1] !== '' && ($format === self::BOTH || $format === self::SLASH)) { Route::set($value[0], '/' . $value[1] . '/', $controller . ':' . $value[2]); } if ($format === self::BOTH || $format === self::NOSLASH) { Route::set($value[0], '/' . $value[1], $controller . ':' . $value[2]); } } $controller = $classMethods = null; }
public static function isBinary($path) { if (false === is_readable($path)) { Exception::raise($path . ' is not readable', 2); } $size = filesize($path); if ($size < 2) { return false; } $data = file_get_contents($path, false, null, -1, 5012); if (false && function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME_ENCODING); $encode = finfo_buffer($finfo, $data, FILEINFO_MIME_ENCODING); finfo_close($finfo); $data = null; return $encode === 'binary'; } $buffer = ''; for ($i = 0; $i < $size; ++$i) { if (isset($data[$i])) { $buffer .= sprintf('%08b', ord($data[$i])); } } $data = null; return preg_match('#^[0-1]+$#', $buffer) === 1; }
public function xml($root, $data, $charset = 'UTF-8') { if (empty($root) || false === ctype_alpha($root)) { Exception::raise('First argument in Response::xml requires a string', 2); return false; } if (false === is_array($data)) { Exception::raise('Second argument in Response::xml requires a array', 2); return false; } $default = '<?xml version="1.0"'; if (is_string($charset)) { $default .= ' encoding="' . $charset . '"'; } $default .= '?><' . $root . '></' . $root . '>'; $xmlElement = new \SimpleXMLElement($default); self::generate($data, $xmlElement); $resp = new DefaultResponse(); DefaultResponse::contentType('text/xml'); $resp->data($xmlElement->asXML()); $xmlElement = null; }