Ejemplo 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);
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 /**
  * Retrieves a SERVER parameter
  *
  * @param string $key    Parameter key
  * @param mixed  $default Default value
  * @return mixed Returns a value if a key is specified,
  *               or an array of SERVER parameters if it isn't.
  */
 public function server($key = null, $default = null)
 {
     if ($key == null) {
         return $this->_server;
     }
     return $this->pixie->arr($this->_server, $key, $default);
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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 . ')';
 }
Ejemplo n.º 6
0
 /**
  * Retrieves a URL parameter
  *
  * @param string $key    Parameter key
  * @param mixed $default Default value
  * @param bool  $filter_xss Whether to filter input for XSS protection
  * @return mixed Returns a value if a key is specified,
  *               or an array of POST parameters if it isn't.
  */
 public function param($key = null, $default = null, $filter_xss = true)
 {
     if ($key == null) {
         return $this->_param;
     }
     $val = $this->pixie->arr($this->_param, $key, $default);
     if ($filter_xss) {
         return $this->filter_xss($val);
     }
     return $val;
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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);
 }