Ver código fonte

slag up routing definition for more speed @techempower #coderwall #pimf #php #framework

gjerokrsteski 11 anos atrás
pai
commit
017ae5d2dc

+ 1 - 1
php-pimf/app/Vanilla/Controller/Hello.php

@@ -10,7 +10,7 @@ class Hello extends Base
    */
   public function indexAction()
   {
-    $this->jsonAction();
+    $this->plaintextAction();
   }
 
   /**

+ 1 - 7
php-pimf/app/Vanilla/routes.php

@@ -1,10 +1,4 @@
 <?php
 return array(
-  new \Pimf\Route('/', array('controller' => 'hello', 'action' => 'index')),
-  new \Pimf\Route('/json', array('controller' => 'hello', 'action' => 'json')),
-  new \Pimf\Route('/queries', array('controller' => 'hello', 'action' => 'queries')),
-  new \Pimf\Route('/db', array('controller' => 'hello', 'action' => 'db')),
-  new \Pimf\Route('/fortunes', array('controller' => 'hello', 'action' => 'fortunes')),
-  new \Pimf\Route('/updates', array('controller' => 'hello', 'action' => 'updates')),
-  new \Pimf\Route('/plaintext', array('controller' => 'hello', 'action' => 'plaintext')),
+  new \Pimf\Route('/:action', array('controller' => 'hello')),
 );

+ 5 - 6
php-pimf/pimf-framework/core/Pimf/Event.php

@@ -111,8 +111,8 @@ class Event
   /**
    * Fire an event and return the first response.
    *
-   * @param string $event
-   * @param \Exception[]  $parameters
+   * @param string       $event
+   * @param \Exception[] $parameters
    *
    * @return mixed
    */
@@ -141,15 +141,14 @@ class Event
    * Fire an event so that all listeners are called.
    *
    * @param string $events
-   * @param array        $parameters
-   * @param bool         $halt
+   * @param array  $parameters
+   * @param bool   $halt
    *
    * @return array|null
    */
   public static function fire($events, $parameters = array(), $halt = false)
   {
-    $responses = array();
-
+    $responses  = array();
     $parameters = (array)$parameters;
 
     // If the event has listeners, iterate through them and call each listener,

+ 2 - 2
php-pimf/pimf-framework/core/Pimf/Logger.php

@@ -162,7 +162,7 @@ class Logger
 
       if (fclose($this->handle) === false) {
         // Failure to close the log file
-        $this->write("Logger failed to close the handle to the log file", 'ERROR_SEVERITY');
+        $this->error('Logger failed to close the handle to the log file');
       }
 
       fclose($this->warnHandle);
@@ -195,7 +195,7 @@ class Logger
 
     $msg .= " " . $severity . ": ";
 
-    //get the file name
+    // get the file name
     $lastSlashIndex = strrpos($script, "/");
     $fileName       = $script;
 

+ 3 - 2
php-pimf/pimf-framework/core/Pimf/Response.php

@@ -141,11 +141,12 @@ class Response
    *
    * @param string $stream Can be a file-path or a string.
    * @param string $name   Name of the stream/file should be shown.
+   * @param boolean $exit Optional for testing
    */
-  public function sendStream($stream, $name)
+  public function sendStream($stream, $name, $exit = true)
   {
     Header::clear();
-    Header::sendDownloadDialog($stream, $name);
+    Header::sendDownloadDialog($stream, $name, $exit);
   }
 
   /**

+ 3 - 1
php-pimf/pimf-framework/core/Pimf/Session/Storages/Cookie.php

@@ -28,13 +28,15 @@ class Cookie extends Storage
    *
    * @param  string $key
    *
-   * @return array
+   * @return array|null
    */
   public function load($key)
   {
     if (Crumb::has(static::PAYLOAD)) {
       return unserialize(base64_decode(Crumb::get(static::PAYLOAD)));
     }
+
+    return null;
   }
 
   /**

+ 6 - 2
php-pimf/pimf-framework/core/Pimf/Util/Header.php

@@ -184,8 +184,9 @@ class Header extends Header\ContentType
    *
    * @param string $fileOrString
    * @param string $fileName
+   * @param boolean $exit Optional for testing
    */
-  public static function sendDownloadDialog($fileOrString, $fileName)
+  public static function sendDownloadDialog($fileOrString, $fileName, $exit = true)
   {
     $disposition = (false !== strpos(Registry::get('env')->getUserAgent(), 'MSIE 5.5')) ? '' : 'attachment; ';
 
@@ -200,6 +201,9 @@ class Header extends Header\ContentType
     } else {
       echo $fileOrString;
     }
-    exit(0);
+
+    if ($exit) {
+      exit(0);
+    }
   }
 }