Beispiel #1
0
 public static function getProfiles()
 {
     if (!isset(self::$profiles)) {
         self::$profiles = Config::get('deploy')->profiles;
     }
     return self::$profiles;
 }
 protected function respondHTML()
 {
     if ($this->error['code'] == 401) {
         $to = urlencode($_SERVER['REQUEST_URI']);
         return \Wave\Utils::redirect('/sign-in?to=' . $to);
     }
     $exception = $this->_data['exception'];
     include_once \Wave\Config::get('wave')->path->views . 'system' . DS . 'exception.php';
 }
Beispiel #3
0
 public static function ceaseIdentity($type = null)
 {
     $config = Config::get('deploy')->auth;
     if ($type === null) {
         $type = $config->persist_type;
     }
     if ($type == 'cookie') {
         Cookie::store($config->cookie->name, '', time() - 86400, $config->cookie->path, $config->cookie->domain);
     }
 }
Beispiel #4
0
 public static function generate()
 {
     $reflector = new Wave\Reflector(Wave\Config::get('wave')->path->controllers);
     $reflected_options = $reflector->execute();
     $all_actions = self::buildRoutes($reflected_options);
     foreach ($all_actions as $profile => $actions) {
         $route_node = new Node();
         foreach ($actions as $action) {
             foreach ($action->getRoutes() as $route) {
                 $route_node->addChild($route, $action);
             }
         }
         Wave\Cache::store(Router::getCacheName($profile, 'table'), $actions);
         Wave\Cache::store(Router::getCacheName($profile, 'tree'), $route_node);
     }
 }
Beispiel #5
0
 public function compile(\Twig_Compiler $compiler)
 {
     $type = $this->getAttribute('type');
     $file = $this->getAttribute('file');
     $extras = $this->getAttribute('extras');
     $priority = $this->getAttribute('priority');
     $cache_tag = null;
     if (!preg_match('/http(s)?\\:\\/\\//', $file)) {
         $file = Wave\Config::get('deploy')->assets . $file;
         $cache_tag = @file_get_contents($file);
         if ($cache_tag !== false) {
             $cache_tag = md5($cache_tag);
         } else {
             $cache_tag = null;
         }
     }
     $compiler->addDebugInfo($this)->write("\$this->env->_wave_register('{$type}', '{$file}', '{$extras}', '{$priority}', '{$cache_tag}');")->raw("\n");
 }
Beispiel #6
0
 public static function getSchema($schema)
 {
     if (!array_key_exists($schema, self::$_schema_cache)) {
         $schema_name = strtr($schema, '_', DIRECTORY_SEPARATOR);
         $schema_file = sprintf(Config::get('wave')->schemas->file_format, $schema_name);
         $schema_path = Config::get('wave')->path->schemas . $schema_file;
         if (is_file($schema_path) && is_readable($schema_path)) {
             $schema_data = (include $schema_path);
             if (!array_key_exists('fields', $schema_data)) {
                 throw new InvalidArgumentException("{$schema} must have a 'fields' definition");
             }
             self::$_schema_cache[$schema] =& $schema_data;
         } else {
             throw new ValidationException("Could not load schema [{$schema}] from file ({$schema_path})");
         }
     }
     return self::$_schema_cache[$schema];
 }
Beispiel #7
0
 public static function getDefaultHandlers()
 {
     if (static::$default_handlers === null) {
         static::$default_handlers = array();
         $log_path = Config::get('wave')->path->logs;
         $log_path .= Config::get('wave')->logger->file->file;
         $log_dir = dirname($log_path);
         if (!is_writable($log_dir)) {
             @mkdir($log_dir, 0770, true);
         }
         $stream_handler = new StreamHandler($log_path, static::getDefaultLevel());
         $stream_handler->pushProcessor(new ExceptionIntrospectionProcessor());
         static::pushDefaultHandler($stream_handler);
         if (PHP_SAPI === 'cli') {
             $cli_handler = new CliHandler(Config::get('wave')->logger->cli->level);
             $cli_handler->setFormatter(new LineFormatter(CliHandler::LINE_FORMAT));
             static::pushDefaultHandler($cli_handler);
         }
     }
     return static::$default_handlers;
 }
Beispiel #8
0
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $path = $this->parser->getStream()->expect(\Twig_Token::STRING_TYPE)->getValue();
     if (!preg_match('/http(s)?\\:\\/\\//', $path)) {
         $path = Wave\Config::get('deploy')->assets . $path;
     }
     $attributes = array();
     if ($this->parser->getStream()->test(\Twig_Token::STRING_TYPE)) {
         $str = $this->parser->getStream()->expect(\Twig_Token::STRING_TYPE)->getValue();
         $attributes['title'] = $str;
         $attributes['alt'] = $str;
     }
     if (!$this->parser->getStream()->test(\Twig_Token::BLOCK_END_TYPE)) {
         $array = $this->parser->getExpressionParser()->parseArrayExpression();
         foreach ($array->getIterator() as $key => $node) {
             $attributes[$key] = $node->getAttribute('value');
         }
     }
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new ImgNode($path, $attributes, $lineno, $this->getTag());
 }
Beispiel #9
0
 public static function getResponseMethod()
 {
     if (self::$_response_method == null) {
         if (PHP_SAPI === 'cli') {
             return Response::FORMAT_CLI;
         } else {
             return Config::get('wave')->response->default_format;
         }
     } else {
         return self::$_response_method;
     }
 }
Beispiel #10
0
 /**
  * Determines the request format (html, json, xml etc) for a request based on the extension in the
  * given url
  *
  * @param string $url
  * @param string|null $default
  *
  * @return string
  */
 protected static function parseFormat($url, $default = null)
 {
     if (null === $default) {
         $default = PHP_SAPI === 'cli' ? 'cli' : Config::get('wave')->response->default_format;
     }
     $path = pathinfo($url);
     return isset($path['extension']) ? $path['extension'] : $default;
 }
Beispiel #11
0
 public static function generate()
 {
     $cache_dir = Config::get('wave')->view->cache;
     if (!file_exists($cache_dir)) {
         @mkdir($cache_dir, 0770, true);
     }
     if (!file_exists($cache_dir)) {
         throw new Exception('Could not generate views, the cache directory does not exist or is not writable');
     }
     // delete caches
     $dir_iterator = new RecursiveDirectoryIterator($cache_dir);
     $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $file) {
         if ($file->getFilename() === '.' || $file->getFilename() === '..') {
             continue;
         }
         $func = $file->isDir() ? 'rmdir' : 'unlink';
         $func($file->getRealPath());
     }
     $self = self::getInstance();
     $source_path = Config::get('wave')->path->views;
     $dir_iterator = new RecursiveDirectoryIterator($source_path);
     $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::CHILD_FIRST);
     $l = strlen($source_path);
     foreach ($iterator as $template) {
         $filename = $template->getFilename();
         if (pathinfo($filename, PATHINFO_EXTENSION) != 'phtml') {
             continue;
         }
         $self->twig->loadTemplate(substr($template, $l));
     }
 }
Beispiel #12
0
 /**
  * @param \Wave\DB $database
  *
  * @return string
  */
 private static function getModelPath(Wave\DB $database)
 {
     $namespace = $database->getNamespace(false);
     $model_directory = Wave\Config::get('wave')->path->models;
     return $model_directory . DS . $namespace . DS;
 }
Beispiel #13
0
 /**
  * @param Action $action
  * @param Request $request
  * @param array $data
  * @param int $invoke_type
  *
  * @throws Http\Exception\UnauthorizedException
  * @throws Http\Exception\NotFoundException
  * @throws Exception
  * @throws Http\Exception\ForbiddenException
  * @return Http\Response
  * @throws Http\Exception\ForbiddenException
  */
 public static final function invoke(Action $action, Request $request, $data = array(), $invoke_type = self::INVOKE_NORMAL)
 {
     list($controller_class, $action_method) = explode('.', $action->getAction(), 2) + array(null, null);
     if (!isset($action_method)) {
         $action_method = Config::get('wave')->controller->default_method;
     }
     if (class_exists($controller_class, true) && method_exists($controller_class, $action_method)) {
         /** @var \Wave\Controller $controller */
         $controller = new $controller_class();
         $controller->_action = $action;
         $controller->_request = $request;
         $controller->_response_method = $request->getFormat();
         $controller->_invoke_method = $invoke_type;
         switch ($controller->_request->getMethod()) {
             case Request::METHOD_GET:
                 $controller->_is_get = true;
                 break;
             case Request::METHOD_POST:
                 $controller->_is_post = true;
                 break;
         }
         $data = array_replace($controller->_request->getData(), $data);
         $controller->_data = $data;
         Hook::triggerAction('controller.before_init', array(&$controller));
         $controller->init();
         if ($invoke_type !== self::INVOKE_SUB_REQUEST && !$action->canRespondWith($request->getFormat())) {
             throw new NotFoundException('The requested action ' . $action->getAction() . ' can not respond with ' . $request->getFormat() . '. (Accepts: ' . implode(', ', $action->getRespondsWith()) . ')', $request);
         } else {
             if (!$action->checkRequiredLevel($request)) {
                 throw new UnauthorizedException('You are not authorized to view this resource');
             } else {
                 if ($action->needsValidation() && !$controller->inputValid($action->getValidationSchema($data))) {
                     return $controller->request();
                 }
             }
         }
         Hook::triggerAction('controller.before_dispatch', array(&$controller));
         $parameters = array();
         foreach ($action->getMethodParameters() as $parameter) {
             list($parameter_name, $parameter_type) = $parameter;
             if (isset($controller->_cleaned[$parameter_name])) {
                 //Try first in validator output
                 $parameters[] = $controller->_cleaned[$parameter_name];
             } elseif (isset($controller->_data[$parameter_name])) {
                 //Then if just using the passed data - there may be a legitimate use for this?
                 $parameters[] = $controller->_data[$parameter_name];
             } elseif ($parameter_type === 'Wave\\Validator\\Result') {
                 //If the validator is requested, give it
                 $parameters[] = $controller->_cleaned;
             } elseif ($parameter_type === get_class($request)) {
                 //If the request is requested, give it
                 $parameters[] = $request;
             } else {
                 //Otherwise place hold. Could maybe get the default value during generation and pass that instead
                 $parameters[] = null;
             }
         }
         try {
             $response = call_user_func_array(array($controller, $action_method), $parameters);
         } catch (InvalidInputException $e) {
             $controller->_input_errors = $e->getViolations();
             $response = $controller->request();
         }
         Hook::triggerAction('controller.after_dispatch', array(&$controller, &$response));
         return $response;
     } else {
         throw new Exception('Could not invoke action ' . $action->getAction() . '. Method ' . $controller_class . '::' . $action_method . '() does not exist', Response::STATUS_SERVER_ERROR);
     }
 }
Beispiel #14
0
 public function setProfile($profile)
 {
     $profiles = Config::get('deploy')->profiles;
     if (!isset($profiles->{$profile})) {
         throw new Exception('BaseURL profile "' . $profile . '" is not defined in deploy configuration');
     } else {
         $this->profile = $profile;
         $this->setBaseURL($profiles->{$profile}->baseurl);
     }
 }
Beispiel #15
0
 /**
  * @param bool $full_namespace
  *
  * @return string
  */
 public function getNamespace($full_namespace = true)
 {
     $ns_prefix = $full_namespace ? Config::get('wave')->model->base_namespace . '\\' : '';
     return $ns_prefix . $this->namespace;
 }