Esempio n. 1
2
 public static function view($type, $view)
 {
     if ($view !== null && View::exists($view) === false) {
         Exception::raise($view . ' view is not found', 2);
     }
     $callRender = array('\\' . get_called_class(), 'render' . ucfirst($type));
     switch ($type) {
         case 'error':
             self::$views[$type] = $view;
             App::on('error', $callRender);
             if (empty(self::$displayErrors)) {
                 self::$displayErrors = ini_get('display_errors');
                 ini_set('display_errors', '0');
             }
             break;
         case 'classes':
         case 'performance':
             self::$views[$type] = $view;
             App::on('terminate', $callRender);
             break;
         default:
             Exception::raise($type . ' is not valid event', 2);
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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);
         }
     }
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 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 ($format === self::BOTH || $format === self::SLASH) {
             $route = $this->prefix . '/' . (empty($value[1]) ? '' : $value[1] . '/');
             Route::set($value[0], $route, $controller . ':' . $value[2]);
         }
         if ($format === self::BOTH || $format === self::NOSLASH) {
             $route = $this->prefix . (empty($value[1]) ? '' : '/' . $value[1]);
             Route::set($value[0], $route, $controller . ':' . $value[2]);
         }
     }
     $controller = $classMethods = null;
 }