Ejemplo n.º 1
0
 /**
  * recurses through the Test subdir and includes classes in each test group subdir,
  * then builds an array of classnames for the tests that will be run
  *
  */
 public function loadTests($test_path = NULL)
 {
     $this->resetStats();
     if ($test_path === NULL) {
         // this seems hackey.  is it?  dunno.
         $test_path = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Security' . DIRECTORY_SEPARATOR . 'Test';
     }
     $test_root = dir($test_path);
     while (false !== ($entry = $test_root->read())) {
         if (is_dir($test_root->path . DIRECTORY_SEPARATOR . $entry) && !preg_match('|^\\.(.*)$|', $entry)) {
             $test_dirs[] = $entry;
         }
     }
     // include_once all files in each test dir
     foreach ($test_dirs as $test_dir) {
         $this_dir = dir($test_root->path . DIRECTORY_SEPARATOR . $test_dir);
         while (false !== ($entry = $this_dir->read())) {
             if (!is_dir($this_dir->path . DIRECTORY_SEPARATOR . $entry) && preg_match('/[A-Za-z]+\\.php/i', $entry)) {
                 $className = "Zend_Environment_Security_Test_" . $test_dir . "_" . basename($entry, '.php');
                 Zend::loadClass($className);
                 $classNames[] = $className;
             }
         }
     }
     $this->_tests_to_run = $classNames;
 }
Ejemplo n.º 2
0
 public function addAdvancedRoute($name, $map, $params = array(), $reqs = array())
 {
     if (!class_exists('Custom_Controller_Router_AdvancedRoute')) {
         Zend::loadClass('Custom_Controller_Router_AdvancedRoute');
     }
     $this->_routes[$name] = new Custom_Controller_Router_AdvancedRoute($map, $params, $reqs);
 }
 public static function autoload($class)
 {
     try {
         Zend::loadClass($class);
     } catch (Zend_Exception $e) {
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Tests that the security filter catches directory injections.
  */
 public function testLoadClassIllegalFilename()
 {
     try {
         Zend::loadClass('/path/to/danger');
     } catch (Zend_Exception $e) {
         $this->assertRegExp('/security(.*)filename/i', $e->getMessage());
         return;
     }
     $this->assertFail('Zend_Exception was expected but never thrown.');
 }
Ejemplo n.º 5
0
 public function getDriver()
 {
     // @todo: when the Mysqli adapter moves out of the incubator,
     // the following trick to allow it to be loaded should be removed.
     $incubator = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'incubator' . DIRECTORY_SEPARATOR . 'library';
     Zend::loadClass('Zend_Db_Adapter_Mysqli', $incubator);
     // @todo: also load any auxiliary classes if necessary, e.g.:
     // Zend_Db_Adapter_Mysqli_Exception
     // Zend_Db_Statement_Mysqli
     // Zend_Db_Statement_Mysqli_Exception
     return 'Mysqli';
 }
 public static function autoload($class)
 {
     try {
         if (self::$withLoader) {
             Zend_Loader::loadClass($class);
         } else {
             Zend::loadClass($class);
         }
     } catch (Zend_Exception $e) {
         return false;
     }
     return true;
 }
Ejemplo n.º 7
0
 public static function autoload($class)
 {
     try {
         if (class_exists('Zend_Version')) {
             Zend_Loader::loadClass($class);
         } else {
             Zend::loadClass($class);
         }
     } catch (Zend_Exception $e) {
         return false;
     }
     return true;
 }
Ejemplo n.º 8
0
 public function setUp()
 {
     if (!class_exists('Zend_Log') || !class_exists('Zend_Log_Adapter_Null')) {
         Zend::loadClass('Zend_Log');
         Zend::loadClass('Zend_Log_Adapter_Null');
     }
     if (!Zend_Log::hasLogger('LOG')) {
         Zend_Log::registerLogger(new Zend_Log_Adapter_Null(), 'LOG');
     }
     $this->_instance->setDirectives(array('logging' => true));
     $this->_instance->save('bar : data to cache', 'bar', array('tag3', 'tag4'));
     $this->_instance->save('bar2 : data to cache', 'bar2', array('tag3', 'tag1'));
     $this->_instance->save('bar3 : data to cache', 'bar3', array('tag2', 'tag3'));
 }
Ejemplo n.º 9
0
/**
 * The Primitus View plugin is a procedural function which implements the logic of
 * the template-level {render} function. It is responsible for either calling the
 * requested controller's render() method to get the template, or simply processing
 * the template in the views/ directory if the controller didn't exist.
 * 
 * You can set template-level variables in the module being rendered by simply setting
 * them in the smarty {render} function. i.e.
 * 
 * {render module="blog" action="view" entry=$entry}
 * 
 * will expose the {$entry} template variable to the blog::view template in /blog/view.tpl
 * 
 * @category   Primitus
 * @package    Primitus
 * @subpackage View
 * @copyright  Copyright (c) 2006 John Coggeshall
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
function Primitus_View_Plugin_Render($params, &$smarty)
{
    if (!isset($params['module'])) {
        throw new Primitus_View_Exception("No module name was provided to render");
    }
    $module = $params['module'];
    if (strtolower(substr($module, strlen($module) - 10)) != "controller") {
        $module .= "Controller";
    }
    $action = isset($params['action']) ? $params['action'] : "indexAction";
    $dispatcher = Primitus::registry('Dispatcher');
    $controllerFile = $dispatcher->formatControllerFile($module);
    if (file_exists($controllerFile)) {
        // Load the Class
        Zend::loadClass($module, $dispatcher->getControllerDirectory());
        $controller = new $module();
        if ($controller instanceof Primitus_Controller_Action_Base) {
            unset($params['module']);
            unset($params['action']);
            if (!empty($params)) {
                $view = Primitus_View::getInstance($module);
                foreach ($params as $key => $value) {
                    $view->assign($key, $value);
                }
            }
            return $controller->render($action);
        } else {
            throw new Primitus_View_Exception("Bad Request");
        }
    } else {
        $view = Primitus_View::getInstance($module);
        unset($params['module']);
        unset($params['action']);
        if (!empty($params)) {
            $view = Primitus_View::getInstance($module);
            foreach ($params as $key => $value) {
                $view->assign($key, $value);
            }
        }
        return $view->render($action);
    }
}
Ejemplo n.º 10
0
 /**
  * load class
  * @param string $className : the class to load
  * @throws Exception
  */
 function __autoload($className)
 {
     if (class_exists('Zend', false)) {
         if (is_int(strrpos($className, '_Interface'))) {
             Zend::loadClass($className);
         } else {
             Zend::loadInterface($className);
         }
     } else {
         if (!defined('__CLASS_PATH__')) {
             define('__CLASS_PATH__', realpath(dirname(__FILE__)));
         }
         $file = __CLASS_PATH__ . '/' . str_replace('_', '/', $className) . '.php';
         if (!file_exists($file)) {
             throw new Exception('Cannot load class file ' . $className);
         } else {
             require_once $file;
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * @param  array $modules
  * @param  array $config
  * @throws Zend_Environment_Exception
  * @return void
  */
 public function __construct($modules, $config = array())
 {
     if (is_array($config)) {
         if (isset($config['cache'])) {
             $this->_cache = $config['cache'];
         }
     }
     if (isset($this->_cache)) {
         if ($data = $this->_cache->load($this->_cachePrefix . 'module')) {
             $this->_data = unserialize($data);
             return;
         }
     }
     if ($modules === null) {
         $modules = array();
         $registry = new Zend_Environment_ModuleRegistry();
         foreach ($registry as $file) {
             $class = rtrim($file->getFilename(), '.php');
             $module = "Zend_Environment_Module_{$class}";
             Zend::loadClass($module);
             try {
                 $modules[] = new $module(strtolower($class));
             } catch (Zend_Environment_Exception $e) {
             }
         }
     } elseif (!is_array($modules)) {
         $modules = array($modules);
     }
     foreach ($modules as $instance) {
         if (!$instance instanceof Zend_Environment_Module_Interface) {
             throw new Zend_Environment_Exception("Module does not implement Zend_Environment_Module_Interface");
         }
         $this->_data[$instance->getId()] = $instance;
     }
     $this->_cache('module', serialize($this->_data));
 }
Ejemplo n.º 12
0
 /**
  * If $performDispatch is FALSE, this method will check if a controller
  * file exists.  This still doesn't necessarily mean that it can be dispatched
  * in the stricted sense, as file may not contain the controller class or the
  * controller may reject the action.
  *
  * If $performDispatch is TRUE, then this method will actually
  * instantiate the controller and call its action.  Calling the action
  * is done by passing a Zend_Controller_Dispatcher_Token to the controller's constructor.
  *
  * @param Zend_Controller_Dispatcher_Token $action
  * @param boolean $performDispatch
  * @return boolean|Zend_Controller_Dispatcher_Token
  */
 protected function _dispatch(Zend_Controller_Dispatcher_Token $action, $performDispatch)
 {
     if ($this->_directory === null) {
         throw new Zend_Controller_Dispatcher_Exception('Controller directory never set.  Use setControllerDirectory() first.');
     }
     $className = $this->formatControllerName($action->getControllerName());
     /**
      * If $performDispatch is FALSE, only determine if the controller file
      * can be accessed.
      */
     if (!$performDispatch) {
         return Zend::isReadable($this->_directory . DIRECTORY_SEPARATOR . $className . '.php');
     }
     Zend::loadClass($className, $this->_directory);
     $controller = new $className();
     if (!$controller instanceof Zend_Controller_Action) {
         throw new Zend_Controller_Dispatcher_Exception("Controller \"{$className}\" is not an instance of Zend_Controller_Action.");
     }
     /**
      * Dispatch
      *
      * Call the action of the Zend_Controller_Action.  It will return either null or a
      * new Zend_Controller_Dispatcher_Token object.  If a Zend_Controller_Dispatcher_Token object is returned, this will be returned
      * back to ZFrontController, which will call $this again to forward to
      * another action.
      */
     $nextAction = $controller->run($this, $action);
     // Destroy the page controller instance
     $controller = null;
     // Return either null (finished) or a Zend_Controller_Dispatcher_Token object (forward to another action).
     return $nextAction;
 }
Ejemplo n.º 13
0
 /**
  * Removes the Role from the registry
  *
  * The $role parameter can either be a Role or a Role identifier.
  *
  * @param  Zend_Acl_Role_Interface|string $role
  * @throws Zend_Acl_Role_Registry_Exception
  * @return Zend_Acl_Role_Registry Provides a fluent interface
  */
 public function remove($role)
 {
     Zend::loadClass('Zend_Acl_Role_Registry_Exception');
     try {
         $roleId = $this->get($role)->getRoleId();
     } catch (Zend_Acl_Role_Registry_Exception $e) {
         throw $e;
     }
     foreach ($this->_roles[$roleId]['children'] as $childId => $child) {
         unset($this->_roles[$childId]['parents'][$roleId]);
     }
     foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
         unset($this->_roles[$parentId]['children'][$roleId]);
     }
     unset($this->_roles[$roleId]);
     return $this;
 }
Ejemplo n.º 14
0
 public function testTableInsert()
 {
     Zend::loadClass('Zend_Db_Table_ZfTestTable');
     $table = $this->getIdentifier(self::TABLE_NAME);
     $id = $this->getIdentifier('id');
     $tab1 = new Zend_Db_Table_ZfTestTable(array('db' => $this->_db, 'name' => $table, 'primary' => $id));
     $nextId = $this->_db->fetchOne("SELECT nextval('" . self::SEQUENCE_NAME . "')");
     $row = array('id' => $nextId, 'title' => 'News Item 3', 'subtitle' => 'Sub title 3', 'body' => 'This is body 1', 'date_created' => '2006-05-03 13:13:13');
     $insertResult = $tab1->insert($row);
     $last_insert_id = $this->_db->lastInsertId($table);
     $this->assertEquals($insertResult, (string) $last_insert_id);
     $this->assertEquals(3, (string) $last_insert_id);
 }
Ejemplo n.º 15
0
 /**
  * Dispatch an HTTP request to a controller/action.
  *
  * @param Zend_Controller_Request_Abstract|null $request
  * @param Zend_Controller_Response_Abstract|null $response
  * @return Zend_Controller_Response_Abstract
  */
 public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
 {
     /**
      * Instantiate default request object (HTTP version) if none provided
      */
     if (null === $request && null === ($request = $this->getRequest())) {
         Zend::loadClass('Zend_Controller_Request_Http');
         $request = new Zend_Controller_Request_Http();
     }
     /**
      * Instantiate default response object (HTTP version) if none provided
      */
     if (null === $response && null === ($response = $this->getResponse())) {
         Zend::loadClass('Zend_Controller_Response_Http');
         $response = new Zend_Controller_Response_Http();
     }
     /**
      * Register request and response objects with plugin broker
      */
     $this->_plugins->setRequest($request)->setResponse($response);
     // Begin dispatch
     try {
         /**
          * Route request to controller/action, if a router is provided
          */
         if (null !== ($router = $this->getRouter())) {
             /**
              * Notify plugins of router startup
              */
             $this->_plugins->routeStartup($request);
             $router->setParams($this->getParams());
             $router->route($request);
             /**
              * Notify plugins of router completion
              */
             $this->_plugins->routeShutdown($request);
         }
         /**
          * Notify plugins of dispatch loop startup
          */
         $this->_plugins->dispatchLoopStartup($request);
         $dispatcher = $this->getDispatcher();
         $dispatcher->setParams($this->getParams());
         /**
          *  Attempt to dispatch the controller/action. If the $request
          *  indicates that it needs to be dispatched, move to the next
          *  action in the request.
          */
         do {
             $request->setDispatched(true);
             /**
              * Notify plugins of dispatch startup
              */
             $this->_plugins->preDispatch($request);
             /**
              * Skip requested action if preDispatch() has reset it
              */
             if (!$request->isDispatched()) {
                 continue;
             }
             /**
              * Dispatch request
              */
             $dispatcher->dispatch($request, $response);
             /**
              * Notify plugins of dispatch completion
              */
             $this->_plugins->postDispatch($request);
         } while (!$request->isDispatched());
         /**
          * Notify plugins of dispatch loop completion
          */
         $this->_plugins->dispatchLoopShutdown();
     } catch (Exception $e) {
         $response->setException($e);
     }
     return $response;
 }
Ejemplo n.º 16
0
Archivo: Db.php Proyecto: fferriere/web
 /**
  * Factory for Zend_Db_Adapter classes.
  *
  * Additional keys are processed as key-value pairs for the adapter config array.
  *
  * @param string $adapterName   Name of the adapter to return:
  *                              'pdo_mysql' -> Zend_Db_Adapter_Pdo_Mysql
  *
  * @param array  $config        An array of adapter configuration keys.
  *
  * @return Zend_Db_Adapter_Abstract
  */
 public static function factory($adapterName, $config = array())
 {
     if (!is_string($adapterName) or !strlen($adapterName)) {
         throw new Zend_Db_Exception('Adapter name must be specified in a string');
     }
     if (!is_array($config)) {
         throw new Zend_Db_Exception('Configuration must be an array');
     }
     $adapterName = strtolower($adapterName);
     // normalize input
     $adapterName = 'Zend_Db_Adapter_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $adapterName)));
     Zend::loadClass($adapterName);
     return new $adapterName($config);
 }
Ejemplo n.º 17
0
 /**
  * load needed classes
  */
 function loadClasses()
 {
     $classname = array('mbox' => 'Zend_Mail_Storage_Mbox', 'mbox-folder' => 'Zend_Mail_Storage_Folder_Mbox', 'maildir' => 'Zend_Mail_Storage_Maildir', 'maildir-folder' => 'Zend_Mail_Storage_Folder_Maildir', 'pop3' => 'Zend_Mail_Storage_Pop3', 'imap' => 'Zend_Mail_Storage_Imap');
     if (isset($classname[$this->type])) {
         Zend::loadClass($classname[$this->type]);
     }
 }
 /**
  * Dispatcher class loader
  *
  * Allows loading prefixed classes from a specific directory; used when 
  * modules are utilized.
  * 
  * @param string $class 
  * @param string $dir 
  * @return false|string Returns false if unable to load class, class name 
  * of class loaded otherwise
  */
 public function loadClass($class, $dir)
 {
     if (class_exists($class, false)) {
         return $class;
     }
     $path = str_replace('_', DIRECTORY_SEPARATOR, $class);
     if (strstr($path, DIRECTORY_SEPARATOR)) {
         $file = substr($path, strrpos($path, DIRECTORY_SEPARATOR));
         $spec = $dir . DIRECTORY_SEPARATOR . $file . '.php';
         if (is_readable($spec)) {
             include_once $spec;
             if (!class_exists($class)) {
                 while (strstr($class, '_')) {
                     $class = substr($class, strpos($class, '_'));
                     if (class_exists($class)) {
                         return $class;
                     }
                 }
                 return false;
             }
             return $class;
         }
     } else {
         Zend::loadClass($class, $dir);
         return $class;
     }
     return false;
 }
Ejemplo n.º 19
0
<?php

/**
 * This example shows how to get the language for all
 * languages written in native letters
 * 
 * So en = english de = deutsch da = dánsk and so on
 */
require_once 'Zend.php';
Zend::loadClass('Zend_Locale');
$locale = new Zend_Locale();
$list = $locale->getLanguageList();
unset($list['no']);
foreach ($list as $language => $content) {
    $lang = new Zend_Locale($language);
    print "\n<br>[" . $language . "] " . $lang->getLanguageDisplay($language);
}
Ejemplo n.º 20
0
 /**
  * Return the current set of options and parameters seen in Json format.
  *
  * @throws Zend_Console_Getopt_Exception
  * @return string
  */
 public function toJson()
 {
     if (!$this->_parsed) {
         $this->parse();
     }
     $j = array();
     foreach ($this->_options as $flag => $value) {
         $j['options'][] = array('option' => array('flag' => $flag, 'parameter' => $value));
     }
     Zend::loadClass('Zend_Json');
     $json = Zend_Json::encode($j);
     return $json;
 }
Ejemplo n.º 21
0
 /**
  * If called without parameter getLibrary() returns the current library,
  * otherwise the library of the stated version.
  *
  * @access public
  * @static 
  * @param integer $version
  * @return Zend_Locale_UTF8_Interface
  * @throws Zend_Locale_UTF8_Exception
  */
 public static function &getLibrary($version = self::CURRENT)
 {
     $_version = self::PHP5;
     switch ($version) {
         case self::AUTO:
             $_version = self::_determineVersion();
             break;
         case self::CURRENT:
             $_version = self::$_current;
             break;
         case self::PHP5:
         case self::PHP6:
             self::$_version = $version;
             break;
         default:
             throw new Zend_Locale_UTF8_Exception('Version is not supported by Zend_Locale_UTF8.');
     }
     /**
      * @todo implement PHP6
      */
     if (!isset(self::$_libraries[$_version])) {
         switch ($_version) {
             case self::PHP6:
                 Zend::loadClass('Zend_Locale_UTF8_PHP6');
                 self::$_libraries[$_version] = new Zend_Locale_UTF8_PHP6();
                 break;
             case self::PHP5:
             default:
                 Zend::loadClass('Zend_Locale_UTF8_PHP5');
                 self::$_libraries[$_version] = new Zend_Locale_UTF8_PHP5();
         }
     }
     return self::$_libraries[$_version];
 }
Ejemplo n.º 22
0
 /**
  * Zend_Measure_Area provides an locale aware class for
  * conversion and formatting of area values
  *
  * Zend_Measure $input can be a locale based input string
  * or a value. $locale can be used to define that the
  * input is made in a different language than the actual one.
  *
  * @param  $value  mixed  - Value as string, integer, real or float
  * @param  $type   type   - OPTIONAL a Zend_Measure_Area Type
  * @param  $locale locale - OPTIONAL a Zend_Locale Type
  * @throws Zend_Measure_Exception
  */
 public function __construct($value, $type, $locale = false)
 {
     if ($locale === null) {
         $locale = $this->_Locale;
     }
     if (!($locale = Zend_Locale::isLocale($locale, true))) {
         throw new Zend_Measure_Exception("language ({$locale}) is a unknown language");
     }
     if ($type === null) {
         $type = self::STANDARD;
     }
     if (strpos($type, '::') !== false) {
         $type = substr($type, 0, strpos($type, '::'));
         $sublib = substr($type, strpos($type, '::') + 2);
     }
     if (!array_key_exists($type, self::$_UNIT)) {
         throw new Zend_Measure_Exception("type ({$type}) is unknown");
     }
     if (empty($sublib)) {
         $sublib = current(self::$_UNIT[$type]);
     }
     $library = 'Zend_Measure_' . key(self::$_UNIT[$type]);
     Zend::loadClass($library);
     $this->_Measurement = new $library($value, $sublib, $locale);
 }
Ejemplo n.º 23
0
function __autoload($class)
{
    Zend::loadClass($class);
}
Ejemplo n.º 24
0
 /**
  * _processValidator() - internal function that is called in the existence of VALID metadata
  * 
  * @return void
  */
 protected static function _processValidators()
 {
     foreach ($_SESSION['__ZF']['VALID'] as $validator_name => $valid_data) {
         Zend::loadClass($validator_name);
         $validator = new $validator_name();
         if ($validator->validate() === false) {
             throw new Zend_Session_Exception("This session is not valid according to {$validator_name}.");
         }
     }
     return;
 }
Ejemplo n.º 25
0
<?php

/**
 * @package    Zend_Measure
 * @subpackage UnitTests
 */
/**
 * Zend_Measure
 */
require_once 'Zend.php';
Zend::loadClass('Zend_Measure');
Zend::loadClass('Zend_Measure_Temperature');
/**
 * PHPUnit test case
 */
require_once 'PHPUnit/Framework/TestCase.php';
/**
 * @package    Zend_Measure
 * @subpackage UnitTests
 */
class Zend_MeasureTest extends PHPUnit_Framework_TestCase
{
    /**
     * test for Angle initialisation
     * expected instance
     */
    public function testMeasureInit()
    {
        $value = new Zend_Measure('100', Zend_Measure::TEMPERATURE, 'de');
        $this->assertTrue($value instanceof Zend_Measure, 'Zend_Measure Object not returned');
    }
Ejemplo n.º 26
0
 public static function loadBehavior($behaviorClassName, $targetElement)
 {
     Zend::loadClass($behaviorClassName, self::$BEHAVIOR_FACTORY_DIRS);
     $newObject = new $behaviorClassName($targetElement);
     if (!$newObject instanceof ZFormElementBehavior) {
         throw new ZFormElementException("{$behaviorClassName} is not an " . 'instance of ZFormElementBehavior');
     }
     return $newObject;
 }
Ejemplo n.º 27
0
 /**
  * Set response class/object
  *
  * Set the response object.  The response is a container for action
  * responses and headers. Usage is optional.
  *
  * If a class name is provided, instantiates a response object.
  *
  * @param string|Zend_Controller_Response_Abstract $response
  * @throws Zend_Controller_Exception if invalid response class
  * @return Zend_Controller_Front
  */
 public function setResponse($response)
 {
     if (is_string($response)) {
         Zend::loadClass($response);
         $response = new $response();
     }
     if (!$response instanceof Zend_Controller_Response_Abstract) {
         throw new Zend_Controller_Exception('Invalid response class');
     }
     $this->_response = $response;
     return $this;
 }
Ejemplo n.º 28
0
 /**
  * If $performDispatch is FALSE, this method will check if a controller
  * file exists.  This still doesn't necessarily mean that it can be dispatched
  * in the stricted sense, as file may not contain the controller class or the
  * controller may reject the action.
  *
  * If $performDispatch is TRUE, then this method will actually
  * instantiate the controller and call its action.  Calling the action
  * is done by passing a Zend_Controller_Dispatcher_Token to the controller's constructor.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param boolean $performDispatch
  * @return void
  */
 protected function _dispatch(Zend_Controller_Request_Abstract $request, $performDispatch = true)
 {
     /**
      * Controller directory check
      */
     if ($this->_directory === null) {
         throw new Zend_Controller_Dispatcher_Exception('Controller directory never set.  Use setControllerDirectory() first');
     }
     /**
      * Get controller name
      *
      * Try request first; if not found, try pulling from request parameter; 
      * if still not found, fallback to default
      */
     $controllerName = $request->getControllerName();
     if (empty($controllerName)) {
         $controllerName = $this->getDefaultController();
     }
     $className = $this->formatControllerName($controllerName);
     /**
      * Determine if controller is dispatchable
      */
     $dispatchable = Zend::isReadable($this->_directory . DIRECTORY_SEPARATOR . $className . '.php');
     /**
      * If $performDispatch is FALSE, only determine if the controller file
      * can be accessed.
      */
     if (!$performDispatch) {
         return $dispatchable;
     }
     /**
      * If not dispatchable, get the default controller; if this is already 
      * the default controller, throw an exception
      */
     if (!$dispatchable) {
         if ($controllerName == $this->getDefaultController()) {
             throw new Zend_Controller_Dispatcher_Exception('Default controller class not defined');
         }
         $className = $this->formatControllerName($this->getDefaultController());
     }
     /**
      * Load the controller class file
      */
     Zend::loadClass($className, $this->_directory);
     /**
      * Perform reflection on the class and verify it's a controller
      */
     $reflection = new ReflectionClass($className);
     if (!$reflection->isSubclassOf(new ReflectionClass('Zend_Controller_Action'))) {
         throw new Zend_Controller_Dispatcher_Exception("Controller \"{$className}\" is not an instance of Zend_Controller_Action");
     }
     /**
      * Get any instance arguments and instantiate a controller object
      */
     $argv = $this->getParams();
     /**
      * Prepend response object to arguments
      */
     array_unshift($argv, $this->getResponse());
     /**
      * Prepend request object to arguments
      */
     array_unshift($argv, $request);
     /**
      * Instantiate controller with arguments
      */
     $controller = $reflection->newInstanceArgs($argv);
     /**
      * Determine the action name
      *
      * First attempt to retrieve from request; then from request params 
      * using action key; default to default action
      */
     $action = $request->getActionName();
     if (empty($action)) {
         $action = $this->getDefaultAction();
     }
     $action = $this->formatActionName($action);
     $invokeArgs = array();
     /**
      * If method does not exist, default to __call()
      */
     if (!$reflection->hasMethod($action)) {
         $invokeArgs = array($action, array());
         $action = '__call';
     }
     $method = $reflection->getMethod($action);
     /**
      * Dispatch the method call
      */
     $request->setDispatched(true);
     $controller->preDispatch();
     if ($request->isDispatched()) {
         // preDispatch() didn't change the action, so we can continue
         $method->invokeArgs($controller, $invokeArgs);
         $controller->postDispatch();
     }
     // Destroy the page controller instance and reflection objects
     $controller = null;
     $reflection = null;
     $method = null;
 }
Ejemplo n.º 29
0
 /**
  * Dispatch to a controller/action
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param Zend_Controller_Response_Abstract $response
  * @return boolean
  */
 public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $this->setResponse($response);
     /**
      * Get controller directories
      */
     $directories = $this->getControllerDirectory();
     /**
      * Get controller class
      */
     $className = $this->_getController($request);
     /**
      * If no class name returned, report exceptional behaviour
      */
     if (!$className) {
         throw new Zend_Controller_Dispatcher_Exception('"' . $request->getControllerName() . '" controller does not exist');
     }
     /**
      * Load the controller class file
      *
      * Attempts to load the controller class file from {@link getControllerDirectory()}.
      */
     Zend::loadClass($className, $this->getControllerDirectory());
     /**
      * Instantiate controller with request, response, and invocation 
      * arguments; throw exception if it's not an action controller
      */
     $controller = new $className($request, $this->getResponse(), $this->getParams());
     if (!$controller instanceof Zend_Controller_Action) {
         throw new Zend_Controller_Dispatcher_Exception("Controller '{$className}' is not an instance of Zend_Controller_Action");
     }
     /**
      * Retrieve the action name
      */
     $action = $this->_getAction($request);
     /**
      * If method does not exist, default to __call()
      */
     $doCall = !method_exists($controller, $action);
     /**
      * Dispatch the method call
      */
     $request->setDispatched(true);
     $controller->preDispatch();
     if ($request->isDispatched()) {
         // preDispatch() didn't change the action, so we can continue
         if ($doCall) {
             $controller->__call($action, array());
         } else {
             $controller->{$action}();
         }
         $controller->postDispatch();
     }
     // Destroy the page controller instance and reflection objects
     $controller = null;
 }
Ejemplo n.º 30
0
 /**
  * Factory for Zend_Db_Adapter classes.
  *
  * Additional keys are processed as key-value pairs for the adapter config array.
  *
  * @param string $adapterName   Name of the adapter to return:
  *                              'pdo_mysql' -> Zend_Db_Adapter_Pdo_Mysql
  *
  * @param array  $config        An array of adapter configuration keys.
  *
  * @return Zend_Db_Adapter_Abstract
  */
 public static function factory($adapterName, $config = array())
 {
     if (!is_string($adapterName) or !strlen($adapterName)) {
         throw new Zend_Db_Exception('Adapter name must be specified in a string');
     }
     if (!is_array($config)) {
         throw new Zend_Db_Exception('Configuration must be an array');
     }
     if (substr($adapterName, 0, 3) == 'pdo') {
         $adapterName = 'Zend_Db_Adapter_Pdo_' . substr($adapterName, 3);
     } else {
         $adapterName = 'Zend_Db_Adapter_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $adapterName)));
     }
     Zend::loadClass($adapterName);
     return new $adapterName($config);
 }