Example #1
0
 public function testCase015()
 {
     $previous = new Yaf_Exception("Previous", 100);
     $exception = new Yaf_Exception("Exception", 200, $previous);
     $this->assertSame($previous, $exception->getPrevious());
     $this->assertEquals('Exception', $exception->getMessage());
     $this->assertEquals(100, $exception->getPrevious()->getCode());
 }
Example #2
0
 /**
  * Loads the section $section from the config file $filename for
  * access facilitated by nested object properties.
  *
  * If the section name contains a ":" then the section name to the right
  * is loaded and included into the properties. Note that the keys in
  * this $section will override any keys of the same
  * name in the sections that have been included via ":".
  *
  * If the $section is null, then all sections in the ini file are loaded.
  *
  * If any key includes a ".", then this will act as a separator to
  * create a sub-property.
  *
  * example ini file:
  *      [all]
  *      db.connection = database
  *      hostname = live
  *
  *      [staging : all]
  *      hostname = staging
  *
  * after calling $data = new Yaf_Config_Ini($file, 'staging'); then
  *      $data->hostname === "staging"
  *      $data->db->connection === "database"
  *
  * @param  string  $filename
  * @param  mixed   $section
  * @param  boolean $readonly
  *
  * @throws Yaf_Config_Exception
  * @return void
  */
 public function __construct($filename, $section = null)
 {
     if (empty($filename)) {
         Yaf_Exception::trigger_error('Unable to find config file ' . $filename, E_USER_ERROR);
         //throw new Yaf_Config_Exception('Filename is not set');
     }
     if (is_array($filename)) {
         $this->_config = $filename;
     } elseif (is_string($filename)) {
         $iniArray = $this->_loadIniFile($filename);
         if (null === $section) {
             // Load entire file
             $dataArray = array();
             foreach ($iniArray as $sectionName => $sectionData) {
                 if (!is_array($sectionData)) {
                     $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
                 } else {
                     $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName);
                 }
             }
             parent::__construct($dataArray, true);
         } else {
             // Load one or more sections
             if (!is_array($section)) {
                 $section = array($section);
             }
             $dataArray = array();
             foreach ($section as $sectionName) {
                 if (!isset($iniArray[$sectionName])) {
                     throw new Yaf_Config_Exception("There is no section '{$sectionName}' in '{$filename}'");
                 }
                 $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray);
             }
             parent::__construct($dataArray, true);
         }
     } else {
         throw new Yaf_Exception_TypeError('Invalid parameters provided, must be path of ini file');
     }
 }
Example #3
0
 public function execute($args)
 {
     $arguments = func_get_args();
     $callback = $arguments[0];
     if (!is_callable($callback)) {
         Yaf_Exception::trigger_error('First argument is expected to be a valid callback', E_USER_WARNING);
     }
     array_shift($arguments);
     return call_user_func_array($callback, $arguments);
 }
Example #4
0
 private function resolveDirectory($class)
 {
     if ($this->isLocalName($class)) {
         $directory = $this->_library;
     } else {
         $directory = $this->_globalLibrary;
     }
     if ($directory == '') {
         Yaf_Exception::trigger_error('Yaf_Loader requires Yaf_Application' . '(which set the library_directory) to be initialized first', E_USER_WARNING);
     }
     return $directory;
 }
Example #5
0
 /**
  * Dispatch an HTTP request to a controller/action.
  *
  * @param Yaf_Request_Abstract|null $request
  * @return void|Yaf_Response_Abstract
  */
 public function dispatch(Yaf_Request_Abstract $request = null)
 {
     /**
      * Instantiate default request object (HTTP version) if none provided
      */
     if ($request == null) {
         $request = $this->getRequest();
     } else {
         $this->setRequest($request);
     }
     if (!$request instanceof Yaf_Request_Abstract) {
         throw new Yaf_Exception_TypeError('Expect a Yaf_Request_Abstract instance');
     }
     if ($request instanceof Yaf_Request_Http) {
         $response = new Yaf_Response_Http();
     } elseif ($request instanceof Yaf_Request_Simple) {
         $response = new Yaf_Response_Cli();
     }
     /**
      * Initialize router
      */
     $router = $this->getRouter();
     if (!$request->isRouted()) {
         /**
          * Notify plugins of router startup
          */
         foreach ($this->_plugins as $plugin) {
             $plugin->routerStartup($request, $response);
         }
         try {
             //@todo here seems there is 2 type of routes
             $router->route($request);
         } catch (Exception $e) {
             if ($this->throwException() == true) {
                 throw $e;
             }
         }
         $this->_fixDefault($request);
         /**
          * Notify plugins of router shutdown
          */
         foreach ($this->_plugins as $plugin) {
             $plugin->routerShutdown($request, $response);
         }
     } else {
         $this->_fixDefault($request);
     }
     $view = $this->initView();
     /**
      * Notify plugins of dispatch loop startup
      */
     foreach ($this->_plugins as $plugin) {
         $plugin->dispatchLoopStartup($request, $response);
     }
     $nested = Yaf_G::iniGet('yaf.forward_limit');
     // Begin dispatch
     try {
         /**
          * Route request to controller/action, if a router is provided
          */
         do {
             /**
              * Notify plugins of dispatch startup
              */
             foreach ($this->_plugins as $plugin) {
                 $plugin->preDispatch($request, $response);
             }
             /**
              * Dispatch request
              */
             $this->handle($request, $response, $view);
             $this->_fixDefault($request);
             /**
              * Notify plugins of dispatch completion
              */
             foreach ($this->_plugins as $plugin) {
                 $plugin->postDispatch($request, $response);
             }
             $nested--;
         } while (!$request->isDispatched() && $nested > 0);
         /**
          * Notify plugins of dispatch loop completion
          */
         foreach ($this->_plugins as $plugin) {
             $plugin->dispatchLoopShutdown($request, $response);
         }
     } catch (Exception $e) {
         if ($this->throwException()) {
             throw $e;
         } else {
             Yaf_Exception::trigger_error($e->getMessage(), E_USER_ERROR);
         }
     }
     if ($nested == 0 && !$request->isDispatched()) {
         throw new Yaf_Exception_DispatchFailed('The max dispatch nesting ' . Yaf_G::iniGet('yaf.forward_limit') . ' was reached');
     }
     if ($this->returnResponse() == false) {
         $response->response();
     }
     return $response;
 }
Example #6
0
 /**
  * Constructor.
  * @param string $message PDO error message
  * @param integer $code PDO error code
  * @param mixed $errorInfo PDO error info
  */
 public function __construct($message, $code = 0, $errorInfo = null)
 {
     $this->errorInfo = $errorInfo;
     parent::__construct($message, $code);
 }