]> jfr.im git - irc/h9k/magirc.git/commitdiff
Slim Framework v1.6.3
authorHal9000 <redacted>
Tue, 5 Jun 2012 08:53:06 +0000 (10:53 +0200)
committerHal9000 <redacted>
Tue, 5 Jun 2012 08:53:06 +0000 (10:53 +0200)
lib/slim/Environment.php
lib/slim/Http/Request.php
lib/slim/Http/Util.php
lib/slim/Log.php
lib/slim/Middleware/SessionCookie.php
lib/slim/Router.php
lib/slim/Slim.php
lib/slim/View.php

index 367dbb0ab476b08a1dd17faab7d01aac2602b646..b6e884b15322af0ebf104e3b699763a818df294d 100644 (file)
@@ -62,7 +62,7 @@ class Slim_Environment implements ArrayAccess, IteratorAggregate {
      * Get environment instance (singleton)
      *
      * This creates and/or returns an Environment instance (singleton)
-     * derived from $_SERVER variables. You may override the global server 
+     * derived from $_SERVER variables. You may override the global server
      * variables by using `Environment::mock()` instead.
      *
      * @param   bool            $refresh    Refresh properties using global server variables?
index 7bcd44b497cc9290439d91a9b3c8c548404d93c7..9ef52900ba81f81505e748b4ad8f70384d967d0a 100644 (file)
@@ -215,7 +215,7 @@ class Slim_Http_Request {
         }
         if ( !isset($this->env['slim.request.form_hash']) ) {
             $this->env['slim.request.form_hash'] = array();
-            if ( $this->isFormData() ) {
+            if ( $this->isFormData() && is_string($this->env['slim.input']) ) {
                 $output = array();
                 if ( function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte']) ) {
                     mb_parse_str($this->env['slim.input'], $output);
index 35b9b285c10e5c4edd8b99936b3d17a70d13a656..f0d8f80489e281ecedeb35db46679f35d4cee6e0 100644 (file)
@@ -342,19 +342,13 @@ class Slim_Http_Util {
     public static function parseCookieHeader( $header ) {
         $cookies = array();
         $header = rtrim($header, "\r\n");
-        $headerPieces = preg_split('@\s*;\s*@', $header);
+        $headerPieces = preg_split('@\s*[;,]\s*@', $header);
         foreach ( $headerPieces as $c ) {
             $cParts = explode('=', $c);
             if ( count($cParts) === 2 ) {
                 $key = urldecode($cParts[0]);
                 $value = urldecode($cParts[1]);
-                if ( isset($cookies[$key]) ) {
-                    if ( is_array($cookies[$key]) ) {
-                        $cookies[$key][] = $value;
-                    } else {
-                        $cookies[$key] = array($cookies[$key], $value);
-                    }
-                } else {
+                if ( !isset($cookies[$key]) ) {
                     $cookies[$key] = $value;
                 }
             }
@@ -378,4 +372,4 @@ class Slim_Http_Util {
         return pack("h*", $data1.$data2);
     }
 
-}
\ No newline at end of file
+}
index f07f959f954568f1b6304c0554477561ebc4cabc..8c93126ddaa6bf57607c4d9a42c8145a8fad6a68 100644 (file)
  * @since   1.0.0
  */
 class Slim_Log {
+    const FATAL = 0;
+    const ERROR = 1;
+    const WARN = 2;
+    const INFO = 3;
+    const DEBUG = 4;
+
     /**
      * @var array
      */
index 1452eb2cc5a43e8162c469a2b1a4efcb95b765fb..8bf462014f794665a8b453e86ccca16ab2c4c77f 100644 (file)
@@ -84,6 +84,25 @@ class Slim_Middleware_SessionCookie extends Slim_Middleware {
         if ( is_string($this->settings['expires']) ) {
             $this->settings['expires'] = strtotime($this->settings['expires']);
         }
+
+        /**
+         * Session
+         *
+         * We must start a native PHP session to initialize the $_SESSION superglobal.
+         * However, we won't be using the native session store for persistence, so we
+         * disable the session cookie and cache limiter. We also set the session
+         * handler to this class instance to avoid PHP's native session file locking.
+         */
+        ini_set('session.use_cookies', 0);
+        session_cache_limiter(false);
+        session_set_save_handler(
+            array($this, 'open'),
+            array($this, 'close'),
+            array($this, 'read'),
+            array($this, 'write'),
+            array($this, 'destroy'),
+            array($this, 'gc')
+        );
     }
 
     /**
@@ -142,4 +161,31 @@ class Slim_Middleware_SessionCookie extends Slim_Middleware {
         }
         session_destroy();
     }
+
+    /**
+     * Session Handler Stubs
+     */
+    public function open( $savePath, $sessionName ) {
+        return true;
+    }
+
+    public function close() {
+        return true;
+    }
+
+    public function read( $id ) {
+        return '';
+    }
+
+    public function write( $id, $data ) {
+        return true;
+    }
+
+    public function destroy( $id ) {
+        return true;
+    }
+
+    public function gc( $maxlifetime ) {
+        return true;
+    }
 }
\ No newline at end of file
index 1ce8a310105e47c210a589388e76f0ada35cfc1a..7d89be8c3feeac6c2ad606e692a38d4a3a058e99 100644 (file)
@@ -41,7 +41,7 @@
  * @author  Josh Lockhart
  * @since   1.0.0
  */
-class Slim_Router implements IteratorAggregate {
+class Slim_Router implements Iterator {
     /**
      * @var Slim_Http_Request
      */
@@ -89,14 +89,6 @@ class Slim_Router implements IteratorAggregate {
         $this->namedRoutes = array();
     }
 
-    /**
-     * Get Iterator
-     * @return ArrayIterator
-     */
-    public function getIterator() {
-        return new ArrayIterator($this->getMatchedRoutes());
-    }
-
     /**
      * Get Request
      * @return Slim_Http_Request
@@ -113,6 +105,14 @@ class Slim_Router implements IteratorAggregate {
         return $this->response;
     }
 
+    /**
+     * Get Current Route
+     * @return Slim_Route|false
+     */
+    public function getCurrentRoute() {
+        return $this->current();
+    }
+
     /**
      * Return routes that match the current request
      * @return array[Slim_Route]
@@ -234,4 +234,44 @@ class Slim_Router implements IteratorAggregate {
         }
         return $this->error;
     }
+
+    /**
+     * Iterator Interface: Rewind
+     * @return void
+     */
+    public function rewind() {
+        reset($this->matchedRoutes);
+    }
+
+    /**
+     * Iterator Interface: Current
+     * @return Slim_Route|false
+     */
+    public function current() {
+        return current($this->matchedRoutes);
+    }
+
+    /**
+     * Iterator Interface: Key
+     * @return int|null
+     */
+    public function key() {
+        return key($this->matchedRoutes);
+    }
+
+    /**
+     * Iterator Interface: Next
+     * @return void
+     */
+    public function next() {
+        next($this->matchedRoutes);
+    }
+
+    /**
+     * Iterator Interface: Valid
+     * @return boolean
+     */
+    public function valid() {
+        return $this->current();
+    }
 }
\ No newline at end of file
index 783888c43f58e23f695895083a16a5c32d602b09..0ca0f5724ac4a622d08723e6e51711aef0dfda39 100644 (file)
@@ -1002,7 +1002,7 @@ class Slim {
      * Invoke hook
      * @param   string  $name       The hook name
      * @param   mixed   $hookArgs   (Optional) Argument for hooked functions
-     * @return  mixed
+     * @return  void
      */
     public function applyHook( $name, $hookArg = null ) {
         if ( !isset($this->hooks[$name]) ) {
@@ -1016,11 +1016,12 @@ class Slim {
             foreach( $this->hooks[$name] as $priority ) {
                 if( !empty($priority) ) {
                     foreach($priority as $callable) {
-                        $hookArg = call_user_func($callable, $hookArg);
+                        call_user_func($callable, $hookArg);
                     }
                 }
             }
-            return $hookArg; } }
+        }
+    }
 
     /**
      * Get hook listeners
@@ -1138,6 +1139,7 @@ class Slim {
             $this->applyHook('slim.before.router');
             $dispatched = false;
             $httpMethodsAllowed = array();
+            $this->router->getMatchedRoutes();
             foreach ( $this->router as $route ) {
                 if ( $route->supportsHttpMethod($this->environment['REQUEST_METHOD']) ) {
                     try {
index 5d9ae67eafaa2f962078ebdd1017fc5c1afbf6c6..300006b38e027ecddc470738a3794170b000ab16 100644 (file)
  * @since   1.0.0
  */
 class Slim_View {
+    /**
+     * @var string Absolute template path
+     */
+    protected $templatePath = '';
+
     /**
      * @var array Key-value array of data available to the template
      */
@@ -107,10 +112,14 @@ class Slim_View {
 
     /**
      * Append data to existing View data
-     * @param   array $data
+     * @param   mixed $data
      * @return  void
+     * @throws  InvalidArgumentException
      */
-    public function appendData( array $data ) {
+    public function appendData( $data ) {
+        if ( !is_array($data) ) {
+            throw new InvalidArgumentException('Cannot append View data, array required');
+        }
         $this->data = array_merge($this->data, $data);
     }
 
@@ -132,6 +141,19 @@ class Slim_View {
         $this->templatesDirectory = rtrim($dir, '/');
     }
 
+    /**
+     * Set template
+     * @param   string $template
+     * @return  void
+     * @throws  RuntimeException If template file does not exist
+     */
+    public function setTemplate( $template ) {
+        $this->templatePath = $this->getTemplatesDirectory() . '/' . ltrim($template, '/');
+        if ( !file_exists($this->templatePath) ) {
+            throw new RuntimeException('View cannot render template `' . $this->templatePath . '`. Template does not exist.');
+        }
+    }
+
     /**
      * Display template
      *
@@ -139,26 +161,38 @@ class Slim_View {
      *
      * @param   string $template Path to template file relative to templates directoy
      * @return  void
+     * @throws  RuntimeException    If template does not exist
      */
     public function display( $template ) {
-        echo $this->render($template);
+        echo $this->fetch($template);
+    }
+
+    /**
+     * Fetch rendered template
+     *
+     * This method return the rendered template as a string
+     *
+     * @param   string $template Path to template file relative to templates directoy
+     * @return  void
+     */
+    public function fetch( $template ) {
+        return $this->render($template);
     }
 
     /**
      * Render template
-     * @param   string $template    Path to template file relative to templates directory
-     * @return  string              Rendered template
-     * @throws  RuntimeException    If template does not exist
+     * @return  string  Rendered template
+     *
+     * DEPRECATION WARNING!
+     *
+     * This method will be made PROTECTED in a future version. Please use `Slim_View::fetch` to
+     * return a rendered template instead of `Slim_View::render`.
      */
     public function render( $template ) {
+        $this->setTemplate($template);
         extract($this->data);
-        $templatePath = $this->getTemplatesDirectory() . '/' . ltrim($template, '/');
-        if ( !file_exists($templatePath) ) {
-            throw new RuntimeException('View cannot render template `' . $templatePath . '`. Template does not exist.');
-        }
         ob_start();
-        require $templatePath;
+        require $this->templatePath;
         return ob_get_clean();
     }
-
 }
\ No newline at end of file