Exemplo n.º 1
0
 /**
  * Gets a session variable
  *
  * @param string $key Variable name, 
  *                    If null all variables will be returned.
  * @param mixed $default Default value
  * @return mixed Session value
  */
 public function get($key = null, $default = null)
 {
     $this->check();
     if ($key === null) {
         return $_SESSION;
     }
     return $this->pixie->arr($_SESSION, $key, $default);
 }
Exemplo n.º 2
0
 /**
  * Loads a group configuration file it has not been loaded before and
  * returns its options. If the group doesn't exist creates an empty one
  *
  * @param string    $name Name of the configuration group to load
  * @return array    Array of options for this group
  */
 public function get_group($name)
 {
     if (!isset($this->groups[$name])) {
         $file = $this->pixie->find_file('config', $name);
         $this->load_group($name, $file);
     }
     return $this->groups[$name]['options'];
 }
Exemplo n.º 3
0
 /**
  * Sets the template to use for rendering
  *
  * @param string   $name The name of the template to use
  * @throws \Exception If specified template is not found
  */
 public function set_template($name)
 {
     $this->name = $name;
     $file = $this->pixie->find_file('views', $name, $this->_extension);
     if ($file == false) {
         throw new \Exception("View {$name} not found.");
     }
     $this->path = $file;
 }
Exemplo n.º 4
0
 /**
  * Removes a relationship between current item and the passed one
  *
  * @param string   $relation Name of the relationship
  * @param \PHPixie\ORM\Model    $model    ORM item to remove relationship with. Can be omitted for 'belongs_to' relationships
  * @return void
  * @throws \Exception If realtionship is not defined
  * @throws \Exception If current item is not in the database yet (isn't considered loaded())
  * @throws \Exception If passed item is not in the database yet (isn't considered loaded())
  */
 public function remove($relation, $model = null)
 {
     if (!$this->loaded()) {
         throw new \Exception("Model must be loaded before you try removing relationships from it.");
     }
     $rels = array_merge($this->has_one, $this->has_many, $this->belongs_to);
     $rel = $this->pixie->arr($rels, $relation, false);
     if (!$rel) {
         throw new \Exception("Model doesn't have a '{$relation}' relation defined");
     }
     if ($rel['type'] != 'belongs_to' && (!$model || !$model->loaded())) {
         throw new \Exception("Model must be loaded before being removed from a has_one or has_many relationship.");
     }
     if ($rel['type'] == 'belongs_to') {
         $key = $rel['key'];
         $this->{$key} = null;
         $this->save();
     } elseif (isset($rel['through'])) {
         $this->conn->query('delete')->table($rel['through'])->where(array(array($rel['key'], $this->_row[$this->id_field]), array($rel['foreign_key'], $model->_row[$model->id_field])))->execute();
     } else {
         $key = $rel['key'];
         $model->{$key} = null;
         $model->save();
     }
     $this->cached = array();
 }
Exemplo n.º 5
0
 /**
  * Refresh routes
  * 
  * @return \PHPixie\I18n
  */
 protected function routesRefresh()
 {
     foreach ($this->pixie->config->get('routes') as $name => $rule) {
         $this->pixie->router->add($this->pixie->route($name, $rule[0], $rule[1], $this->pixie->arr($rule, 2, null)));
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Initializes the routed Controller and executes specified action
  *
  * @return \PHPixie\Response A Response object with the body and headers set
  */
 public function execute()
 {
     $class = $this->param('namespace', $this->pixie->app_namespace) . 'Controller\\' . ucfirst($this->param('controller'));
     $controller = $this->pixie->controller($class);
     $controller->request = $this;
     $controller->run($this->param('action'));
     return $controller->response;
 }
Exemplo n.º 7
0
 /**
  * This method is used only by preg_replace_callback() in method match() instead of making anonymous function
  * to avoid fatal memory leak on some server configurations
  */
 protected function rule($str)
 {
     $str = $str[0];
     $regexp = '[a-zA-Z0-9\\-\\._]+';
     if (is_array($this->temp_rule)) {
         $regexp = $this->pixie->arr($this->temp_rule[1], str_replace(array('<', '>'), '', $str), $regexp);
     }
     return '(?P' . $str . $regexp . ')';
 }
Exemplo n.º 8
0
 /**
  * Displays the error page. If you set $display_errors to false
  * only a small error message will be displayed.
  *
  * @param \Exception $exception Exception to display
  * @return void
  */
 public function render_exception_page($exception)
 {
     if (ob_get_length() > 0) {
         ob_end_clean();
     }
     $status = '503 Service Temporarily Unavailable';
     if ($exception instanceof \PHPixie\Exception\PageNotFound) {
         $status = '404 Not Found';
     }
     header($_SERVER["SERVER_PROTOCOL"] . ' ' . $status);
     header("Status: {$status}");
     if (!$this->display_errors) {
         echo $status;
     } else {
         $view = $this->pixie->view('debug');
         $view->exception = $exception;
         $view->log = $this->logged;
         echo $view->render();
     }
 }
Exemplo n.º 9
0
 /**
  * Gets the value of a cookie
  *
  * @param string $key     Cookie name
  * @param mixed $default Default value
  * @return mixed Cookie value
  */
 public function get($key, $default = null)
 {
     return $this->pixie->arr($this->cookies, $key, $default);
 }
Exemplo n.º 10
0
 /**
  * Gets a field value
  *
  * @param   string $field Field name
  * @param   mixed  $default Default value to return
  * @return  mixed  Field value
  */
 public function get($field, $default = null)
 {
     return $this->pixie->arr($this->input, $field, $default);
 }