Subversion Repositories PHPX

Rev

Rev 29 | Rev 34 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29 Rev 31
Line 55... Line 55...
55
   *   already initialized.
55
   *   already initialized.
56
   * @return Application
56
   * @return Application
57
   */
57
   */
58
  public static function getInstance(Application $instance = null)
58
  public static function getInstance(Application $instance = null)
59
  {
59
  {
60
    if (is_null(self::$_instance))
60
    if (self::$_instance === null)
61
    {
61
    {
62
      self::$_instance = ($instance === null) ? new self() : $instance;
62
      self::$_instance = ($instance === null) ? new self() : $instance;
63
    }
63
    }
64
   
64
   
65
    return self::$_instance;
65
    return self::$_instance;
66
  }
66
  }
67
 
67
 
68
  /**
68
  /**
69
   * Getter for properties
69
   * Getter for properties
70
   *
70
   *
71
   * @param string $name
71
   * @param string $name
72
   * @throws ModelPropertyException
72
   * @throws ModelPropertyException
73
   * @return mixed
73
   * @return mixed
74
   */
74
   */
75
  public function __get($name)
75
  public function __get($name)
76
  {
76
  {
77
    /* Support for Object-Relational Mappers */
77
    /* Support for Object-Relational Mappers */
78
    if (strpos($name, 'persistent') === 0)
78
    if (strpos($name, 'persistent') === 0)
79
    {
79
    {
80
      $class = get_class($this);
80
      $class = get_class($this);
81
      return $class::${
81
      return $class::${
82
        $name};
82
        $name};
83
    }
83
    }
84
 
84
 
85
    $method = 'get' . ucfirst($name);
85
    $method = 'get' . ucfirst($name);
86
 
86
 
87
    if (method_exists($this, $method))
87
    if (method_exists($this, $method))
88
    {
88
    {
89
      return $this->$method();
89
      return $this->$method();
90
    }
90
    }
91
 
91
 
92
    if (property_exists($this, "_$name"))
92
    if (property_exists($this, "_$name"))
93
    {
93
    {
94
      return $this->{"_$name"};
94
      return $this->{"_$name"};
95
    }
95
    }
96
 
96
 
97
    return $this->$name;
97
    return $this->$name;
98
  }
98
  }
99
 
99
 
100
  /**
100
  /**
101
   * Setter for properties
101
   * Setter for properties
102
   *
102
   *
103
   * @param string $name
103
   * @param string $name
104
   * @param mixed $value  The new property value before assignment
104
   * @param mixed $value  The new property value before assignment
105
   * @throws ModelPropertyException
105
   * @throws ModelPropertyException
106
   */
106
   */
107
  public function __set($name, $value)
107
  public function __set($name, $value)
108
  {
108
  {
109
    $method = 'set' . ucfirst($name);
109
    $method = 'set' . ucfirst($name);
110
 
110
 
111
    if (method_exists($this, $method))
111
    if (method_exists($this, $method))
112
    {
112
    {
113
      return $this->$method($value);
113
      return $this->$method($value);
114
    }
114
    }
115
 
115
 
116
    if (property_exists($this, "_$name"))
116
    if (property_exists($this, "_$name"))
117
    {
117
    {
118
      $this->{"_$name"} = $value;
118
      $this->{"_$name"} = $value;
119
      return $this->{"_$name"};
119
      return $this->{"_$name"};
120
    }
120
    }
121
 
121
 
122
    /* NOTE: Attempts to set other properties are _silently_ _ignored_ */
122
    /* NOTE: Attempts to set other properties are _silently_ _ignored_ */
123
  }
123
  }
124
 
124
 
125
  /**
125
  /**
126
   * Runs the application, setting up session management and
126
   * Runs the application, setting up session management and
127
   * constructing the controller indicated by the URI
127
   * constructing the controller indicated by the URI
128
   */
128
   */
Line 162... Line 162...
162
   *   <code>null</code> if there is no such <var>$key</var>
162
   *   <code>null</code> if there is no such <var>$key</var>
163
   *   in <var>$array</var>
163
   *   in <var>$array</var>
164
   */
164
   */
165
  public static function getParam($key, array $array = null)
165
  public static function getParam($key, array $array = null)
166
  {
166
  {
167
    if (is_null($array))
167
    if ($array === null)
168
    {
168
    {
169
      $array = $_GET;
169
      $array = $_GET;
170
    }
170
    }
171
   
171
   
172
    return isset($array[$key]) ? $array[$key] : null;
172
    return isset($array[$key]) ? $array[$key] : null;
Line 240... Line 240...
240
    {
240
    {
241
      /* FastCGI */
241
      /* FastCGI */
242
      $url = self::getParam('URL', $_SERVER);
242
      $url = self::getParam('URL', $_SERVER);
243
      if ($url === null)
243
      if ($url === null)
244
      {
244
      {
-
 
245
        /* Server/PHP too old, compute URI */
-
 
246
        $url = self::getParam('REQUEST_URI', $_SERVER);
-
 
247
        if (preg_match('/^[^?]+/', $url, $matches) > 0)
-
 
248
        {
-
 
249
          $url = $matches[0];
-
 
250
        }
-
 
251
        else
-
 
252
        {
-
 
253
          /* Has .php in it, but at least it works */
-
 
254
          $url = self::getParam('SCRIPT_NAME', $_SERVER);
-
 
255
          if ($url === null)
-
 
256
          {
245
        throw new Exception(
257
            throw new Exception(
246
          'Neither $_SERVER["SCRIPT_URL"] nor $_SERVER["URL"] is available, cannot continue.');
258
              'None of $_SERVER["SCRIPT_URL"], $_SERVER["URL"],'
-
 
259
              . ' $_SERVER["REQUEST_URI"], or $_SERVER["SCRIPT_NAME"]'
-
 
260
              . ' is available, cannot continue.');
-
 
261
          }
-
 
262
        }
247
      }
263
      }
248
    }
264
    }
249
   
265
   
250
    $query = (!is_null($controller) ? 'controller=' . $controller : '')
266
    $query = (($controller !== null) ? 'controller=' . $controller : '')
251
           . (!is_null($action) ? '&action=' . $action : '')
267
           . (($action !== null) ? '&action=' . $action : '')
252
           . (!is_null($id) ? '&id=' . $id : '');
268
           . (($id !== null) ? '&id=' . $id : '');
253
   
269
   
254
    return $url . ($query ? '?' . $query : '');
270
    return $url . ($query ? '?' . $query : '');
255
  }
271
  }
256
   
272
   
257
  /**
273
  /**
258
   * Performs a server-side redirect within the application
274
   * Performs a server-side redirect within the application
259
   */
275
   */
260
  public static function redirect($query = '')
276
  public static function redirect($query = '')
261
  {
277
  {
262
    $script_uri = self::getParam('SCRIPT_URI', $_SERVER);
278
    $script_uri = self::getParam('SCRIPT_URI', $_SERVER);
263
    if (is_null($script_uri))
279
    if ($script_uri === null)
264
    {
280
    {
265
      /* Server/PHP too old, compute URI */
281
      /* Server/PHP too old, compute URI */
266
      if (preg_match('/^[^?]+/',
282
      if (preg_match('/^[^?]+/',
267
          self::getParam('REQUEST_URI', $_SERVER), $matches) > 0)
283
          self::getParam('REQUEST_URI', $_SERVER), $matches) > 0)
268
      {
284
      {