function start($environment = "dev") { try { require_once 'Zend/Loader/PluginLoader.php'; Zend_Loader::registerAutoload(); # Inicializa o Config $fConfig = new Zend_Config_Ini($this->_basepath . "/application/config/config.ini", $environment); # start a session app Zend_Session::start(); # load env data $db = $fConfig->application->db; # Register the session Zend_Registry::set("db", $db); # start the front $front = Zend_Controller_Front::getInstance(); //Set the Layout Zend_Layout::startMvc(array("layoutPath" => $this->_basepath . "/application/layout/")); $front->throwExceptions(true); $front->setParam('noViewRendred', true); $front->setParam('noErrorHandler', true); $front->setControllerDirectory($this->_basepath . "/application/modules/default/controllers/"); $front->dispatch(); } catch (Exception $e) { $contentType = "text/html"; header("Content-Type: {$contentType}; charset=utf-8"); var_dump($e->getMessage()); } }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); Zend_Loader::registerAutoload(); // TODO Auto-generated UserServiceTest::setUp() $this->UserService = new App_UserService(); }
function GoogleContactsAuth($GoogleContactsEmail, $GoogleContactsPass) { include_once 'Loader.php'; Zend_Loader::registerAutoload(); $GoogleContactsService = 'cp'; $GoogleContactsClient = Zend_Gdata_ClientLogin::getHttpClient($GoogleContactsEmail, $GoogleContactsPass, $GoogleContactsService); return $GoogleContactsClient; }
public static function prepare() { self::setupEnvironment(); Zend_Loader::registerAutoload(); self::setupRegistry(); self::setupConfiguration(); self::setupFrontController(); self::setupView(); self::setupDatabase(); }
public static function registerZend() { if (self::$zendLoaded) { return; } set_include_path(sfConfig::get('app_zend_lib_dir') . PATH_SEPARATOR . get_include_path()); require_once sfConfig::get('app_zend_lib_dir') . '/Zend/Loader.php'; Zend_Loader::registerAutoload(); self::$zendLoaded = true; }
/** * Controller Startup Initialisation * Add APP/vendor to include path * * @throws Exception */ public function startup() { $include = get_include_path(); $include .= PATH_SEPARATOR . APP . 'vendors' . DS; $successful = set_include_path($include); if (!$successful) { throw new Exception('ZendComponent failed to set include path.', E_ERROR); } require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); }
/** * Constructor */ public function init() { // Zend must be in the include path in order for its classes to load each other $includePath = get_include_path(); $zendPath = $this->getResourcePath('zend'); if (strpos($includePath, $zendPath) === FALSE) { $includePath .= ":{$zendPath}"; set_include_path($includePath); } // Register the Zend autoloader for easy access to its libraries require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); }
/** * Constructor * * Initialize environment, root path, and configuration. * * @param string $env * @param string|null $root * @return void */ public function __construct($root = null) { if (null === $root) { $root = realpath(dirname(__FILE__) . '/../'); } $this->_root = $root; // Set up autoload. Zend_Loader::registerAutoload(); Zend_SetupInit::setupInit(); $this->_front = Zend_Controller_Front::getInstance(); $this->_initErrorReporting(); $tmz = Zend_ConfigSettings::setupTimeZone(); date_default_timezone_set($tmz); }
/** * Setup * * @param Zend_Config $config */ public function setup(Zend_Config $config) { // Use non-default autoload function? $class = $config->get('class'); // Allow loading multiple loaders if ($class instanceof Zend_Config) { $classes = $class->toArray(); } else { $classes = (array) $class; } // Register autoload foreach (array_reverse($classes) as $loader) { Zend_Loader::registerAutoload($loader); } }
public static function prepare() { self::setupEnvironment(); Zend_Loader::registerAutoload(); self::setupRegistry(); self::setupConfiguration(); self::setupLogger(); self::setupFrontController(); self::setupView(); self::setupLayout(); self::setupDatabase(); self::setupCache(); self::setupRouter(); self::setupPlugins(); self::setupApplication(); self::setupAcl(); }
public static function run($config, $helpers) { try { Zend_Loader::registerAutoload(); $cnf = new Zend_Config($config); Zend_Registry::set('cnf', $cnf); self::setDbAdapter(); if (file_exists($cnf->path->system . 'routes.php')) { include_once $cnf->path->system . 'routes.php'; } $auth = Zend_Auth::getInstance(); //$acl=""; if (file_exists($cnf->path->system . 'acl.php')) { include_once $cnf->path->system . 'acl.php'; } //$acl = new AuthAcl(); $request = new Zend_Controller_Request_Http(); $front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new AuthControllerPlugin($auth, $acl)); $front->addModuleDirectory($cnf->path->modules); $front->setBaseUrl($cnf->url->base)->throwexceptions(true)->setRouter($router)->setRequest($request)->setDefaultModule("default")->setDefaultControllerName("index"); Zend_Layout::startMvc(array('layoutPath' => $cnf->path->layouts, 'layout' => 'index')); $layout = Zend_Layout::getMvcInstance(); $view = $layout->getView(); $layout->setViewSuffix('phtml'); $layout->setView($view); //$view->setBasePath($cnf->path->views); // Helpers connecting foreach ($helpers as $name => $path) { $view->addHelperPath($path, $name); } $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer(); $viewRenderer->setView($view)->setViewSuffix('tpl'); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); if (file_exists($cnf->path->system . 'main_index.php')) { include_once $cnf->path->system . 'main_index.php'; } //Zend_Controller_Front::run($cnf->path->controllers); //Zend_Controller_Front::dispatch(); $front->dispatch(); } catch (Exception $e) { Error::catchException($e); } }
/** * Constructor * * Initialize environment, root path, and configuration. * * @param string $env * @param string|null $root * @return void */ public function __construct($env, $root = null) { $this->_setEnv($env); if (null === $root) { $root = realpath(dirname(__FILE__) . '/../'); } $this->_root = $root; $this->initPhpConfig(); $this->_front = Zend_Controller_Front::getInstance(); // set the test environment parameters if ($env == 'test') { // Enable all errors so we'll know when something goes wrong. error_reporting(E_ALL | E_STRICT); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); $this->_front->throwExceptions(true); } // Set up autoload. Zend_Loader::registerAutoload(); }
/** * Run the AMF server */ public function run() { $enable = $this->get_enable(); if (empty($enable)) { die; } include "Zend/Loader.php"; Zend_Loader::registerAutoload(); //retrieve the api name $classpath = optional_param('classpath', 'user', PARAM_ALPHA); require_once dirname(__FILE__) . '/../../' . $classpath . '/external.php'; /// run the Zend AMF server $server = new Zend_Amf_Server(); $debugmode = get_config($this->get_protocolid(), 'debug'); if (!empty($debugmode)) { $server->setProduction(false); } else { $server->setProduction(true); } $server->setClass($classpath . "_external"); $response = $server->handle(); echo $response; }
public function run() { $enable = $this->get_enable(); if (empty($enable)) { die; } include "Zend/Loader.php"; Zend_Loader::registerAutoload(); Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception'); // retrieve the token from the url // if the token doesn't exist, set a class containing only get_token() $token = optional_param('token', null, PARAM_ALPHANUM); if (empty($token)) { $server = new Zend_XmlRpc_Server(); $server->setClass("ws_authentication", "authentication"); echo $server->handle(); } else { // if token exist, do the authentication here /// TODO: following function will need to be modified $user = webservice_lib::mock_check_token($token); if (empty($user)) { throw new moodle_exception('wrongidentification'); } else { /// TODO: probably change this global $USER; $USER = $user; } //retrieve the api name $classpath = optional_param(classpath, null, PARAM_ALPHA); require_once dirname(__FILE__) . '/../../' . $classpath . '/external.php'; /// run the server $server = new Zend_XmlRpc_Server(); $server->setClass($classpath . "_external", $classpath); echo $server->handle(); } }
/** * @group ZF-6605 */ public function testRegisterAutoloadShouldEnableZendLoaderAutoloaderAsFallbackAutoloader() { if (!function_exists('spl_autoload_register')) { $this->markTestSkipped("spl_autoload() not installed on this PHP installation"); } $this->setErrorHandler(); Zend_Loader::registerAutoload(); $this->assertContains('deprecated', $this->error); $autoloader = Zend_Loader_Autoloader::getInstance(); $this->assertTrue($autoloader->isFallbackAutoloader()); foreach (spl_autoload_functions() as $function) { if (is_array($function)) { $class = $function[0]; if ($class == 'Zend_Loader_Autoloader') { spl_autoload_unregister($function); break; } } } }
<?php error_reporting(E_ALL | E_STRICT); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); date_default_timezone_set('America/Toronto'); /* * Setup libraries & autoloaders */ define('ROOT_DIR', dirname(dirname(__FILE__))); $paths = array(get_include_path(), ROOT_DIR . '/library', ROOT_DIR . '/application/forms', ROOT_DIR . '/application/models', ROOT_DIR . '/application/models/generated'); set_include_path(implode(PATH_SEPARATOR, $paths)); require 'Zend/Loader.php'; require 'Doctrine.php'; Zend_Loader::registerAutoload('Zend_Loader'); #spl_autoload_register(array('Doctrine', 'autoload')); /* * Set super-global data */ Doctrine_Manager::connection("mysql://root@localhost/munch"); /* * Configure Doctrine */ Zend_Registry::set('doctrine_config', array('data_fixtures_path' => ROOT_DIR . '/application/doctrine/data/fixtures', 'models_path' => ROOT_DIR . '/application/models', 'migrations_path' => ROOT_DIR . '/application/doctrine/migrations', 'sql_path' => ROOT_DIR . '/application/doctrine/data/sql', 'yaml_schema_path' => ROOT_DIR . '/application/doctrine/schema'));
public function testLoaderUnregisterAutoload() { if (!function_exists('spl_autoload_register')) { $this->markTestSkipped("spl_autoload() not installed on this PHP installation"); } Zend_Loader::registerAutoload(); $autoloaders = spl_autoload_functions(); $expected = array('Zend_Loader', 'autoload'); $found = false; foreach($autoloaders as $function) { if ($expected == $function) { $found = true; break; } } $this->assertTrue($found, "Failed to register Zend_Loader::autoload() with spl_autoload"); Zend_Loader::registerAutoload('Zend_Loader', false); $autoloaders = spl_autoload_functions(); $expected = array('Zend_Loader', 'autoload'); $found = false; foreach($autoloaders as $function) { if ($expected == $function) { $found = true; break; } } $this->assertFalse($found, "Failed to unregister Zend_Loader::autoload() with spl_autoload"); }
/** * Generate web service description array from the phpdoc for a given class * @param string $file the class file * @param string $class the class name * @return array description * * ------- Example ------- * Docnlock: @ subparam string $params:searches->search - the string to search * $params is considered as the first element, searches the second, and search the terminal * Except the terminal element, all other will be generated as an array * => left element are generated as an associative array. * If the following character is ':' so the right element is a key named 'multiple:element_name' * If the following character is '->' so the right element will be named 'element_name' * Rule: If a key is named 'multiple:xxx' other key must be 'multiple:yyy' Docblock of mock_function --------------------------- @ param array|struct $params @ subparam string $params:searches->search - the string to search @ subparam string $params:searches->search2 optional - optional string to search @ subparam string $params:searches->search3 - the string to search @ subparam string $params:airport->planes:plane->company->employees:employee->name - name of a employee of a company of a plane of an airport @ return array users @ subreturn integer $users:user->id @ subreturn integer $users:user->auth Generated description array --------------------------- description["mock_function"]=> array(3) { ["params"]=> array(2) { ["multiple:searches"]=> array(2) { ["search"]=> string(6) "string" ["search3"]=> string(6) "string" } ["multiple:airport"]=> array(1) { ["planes"]=> array(1) { ["multiple:plane"]=> array(1) { ["company"]=> array(1) { ["employees"]=> array(1) { ["multiple:employee"]=> array(1) { ["name"]=> string(6) "string" } } } } } } } ["optional"]=> array(1) { ["multiple:searches"]=> array(1) { ["search2"]=> string(6) "string" } } ["return"]=> array(1) { ["multiple:user"]=> array(13) { ["id"]=> string(7) "integer" ["auth"]=> string(7) "integer" } } */ public static function generate_webservice_description($file, $class) { require_once $file; require_once "Zend/Loader.php"; Zend_Loader::registerAutoload(); $reflection = Zend_Server_Reflection::reflectClass($class); $description = array(); foreach ($reflection->getMethods() as $method) { $docBlock = $method->getDocComment(); //retrieve the return and add it into the description if not array|object preg_match_all('/@return\\s+(\\w+)\\s+((?:\\$)?\\w+)/', $docBlock, $returnmatches); //retrieve the subparam and subreturn preg_match_all('/\\s*\\*\\s*@(subparam|subreturn)\\s+(\\w+)\\s+(\\$\\w+(?::\\w+|->\\w+)+)((?:\\s+(?:optional|required|multiple))*)/', $docBlock, $matches); /// process every @subparam and @subreturn line of the docblock for ($i = 0; $i < sizeof($matches[1]); $i++) { /// identify the description type of the docblock line: is it params, optional or return (first key of a description method array) switch ($matches[1][$i]) { case "subparam": if (strpos($matches[4][$i], "optional") !== false) { $descriptiontype = "optional"; } else { $descriptiontype = "params"; } break; case "subreturn": $descriptiontype = "return"; break; } /// init description[method] if (empty($description[$method->getName()])) { $description[$method->getName()] = array(); } /// directly set description[method][return] if the return value is a primary type if (strpos($returnmatches[1][0], "object") === false && strpos($returnmatches[1][0], "array") === false) { $description[$method->getName()]['return'] = array($returnmatches[2][0] => $returnmatches[1][0]); } ///algorythm parts ///1. We compare the string to the description array /// When we find a attribut that is not in the description, we retrieve all the rest of the string ///2. We create the missing part of the description array, starting from the end of the rest of the string ///3. We add the missing part to the description array ///Part 1. /// extract the first part into $param (has to be $params in the case of @subparam, or anything in the case of $subreturn) /// extract the second part if (strpos($matches[3][$i], "->") === false || strpos($matches[3][$i], ":") !== false && strpos($matches[3][$i], ":") < strpos($matches[3][$i], "->")) { $separator = ":"; $separatorsize = 1; } else { $separator = "->"; $separatorsize = 2; } $param = substr($matches[3][$i], 1, strpos($matches[3][$i], $separator) - 1); //first element/part/array //for example for the line @subparam string $params:students->student->name // @params is the first element/part/array of this docnlock line // students is the second element/part/array // ... // name is the terminal element, this element will be generated as String here $otherparam = substr($matches[3][$i], strpos($matches[3][$i], $separator) + $separatorsize); //rest of the line $parsingdesc = $description[$method->getName()]; //$pasingdesc is the current position of the algorythm into the description array //it is used to check if a element already exist into the description array if (!empty($parsingdesc) && array_key_exists($descriptiontype, $parsingdesc)) { $parsingdesc = $parsingdesc[$descriptiontype]; } $descriptionpath = array(); //we save in this variable the description path (e.g all keys to go deep into the description array) //it will be used to know where to add a new part the description array $creationfinished = false; //it's used to stop the algorythm when we find a new element that we can add to the descripitoin unset($type); /// try to extract the other elements and add them to the descripition id there are not already in the description while (!$creationfinished && (strpos($otherparam, ":") || strpos($otherparam, "->"))) { if (strpos($otherparam, "->") === false || strpos($otherparam, ":") !== false && strpos($otherparam, ":") < strpos($otherparam, "->")) { $type = $separator; $separator = ":"; $separatorsize = 1; } else { $type = $separator; $separator = "->"; $separatorsize = 2; } $param = substr($otherparam, 0, strpos($otherparam, $separator)); $otherparam = substr($otherparam, strpos($otherparam, $separator) + $separatorsize); if ($type == ":") { /// this element is not already in the description array yet and it is a non associative array /// we add it (and its sub structure) to the description array if (!array_key_exists('multiple:' . $param, $parsingdesc)) { $desctoadd = webservice_lib::create_end_of_descriptionline(":" . $param . $separator . $otherparam, $matches[2][$i]); if (empty($descriptionpath)) { if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) { $desctoadd = array($descriptiontype => $desctoadd); } $paramtoadd = $descriptiontype; } else { $paramtoadd = 'multiple:' . $param; } webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath); $creationfinished = true; // we do not want to keep going to parse this line, // neither add again the terminal element of the line to the descripiton } else { if (empty($descriptionpath)) { $descriptionpath[] = $descriptiontype; } $descriptionpath[] = 'multiple:' . $param; $parsingdesc = $parsingdesc['multiple:' . $param]; } } else { /// this element is not in the description array yet and it is a associative array /// we add it (and its sub structure) to the description array if (!array_key_exists($param, $parsingdesc)) { $desctoadd = webservice_lib::create_end_of_descriptionline("->" . $param . $separator . $otherparam, $matches[2][$i]); if (empty($descriptionpath)) { if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) { $desctoadd = array($descriptiontype => $desctoadd); } $paramtoadd = $descriptiontype; } else { $paramtoadd = $param; } webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath); $creationfinished = true; // we do not want to keep going to parse this line, // neither add again the terminal element of the line to the descripiton } else { if (empty($descriptionpath)) { $descriptionpath[] = $descriptiontype; } $descriptionpath[] = $param; $parsingdesc = $parsingdesc[$param]; } } } /// Add the "terminal" element of the line to the description array if (!$creationfinished) { if (!empty($type) && $type == ":") { $desctoadd = webservice_lib::create_end_of_descriptionline($separator . $otherparam, $matches[2][$i]); if (empty($descriptionpath)) { if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) { $desctoadd = array($descriptiontype => $desctoadd); } $paramtoadd = $descriptiontype; } else { $paramtoadd = 'multiple:' . $param; } webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath); } else { $desctoadd = webservice_lib::create_end_of_descriptionline($separator . $otherparam, $matches[2][$i]); if (empty($descriptionpath)) { if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) { $desctoadd = array($descriptiontype => $desctoadd); } $paramtoadd = $descriptiontype; } else { $paramtoadd = $param; } webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath); } } } } // echo "<pre>"; // var_dump($description); // echo "</pre>"; return $description; }
<?php /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; // Register Zend's autoloader Zend_Loader::registerAutoload(); // Register Zym Doctrine autoloader Zend_Loader::registerAutoload('Zym_Loader_Autoload_Doctrine'); // Unregister Zym Doctrine autoloader Zend_Loader::registerAutoload('Zym_Loader_Autoload_Doctrine', false);
/** * Run Zend SOAP server * @global <type> $CFG * @global <type> $USER */ public function run() { $enable = $this->get_enable(); if (empty($enable)) { die; } global $CFG; include "Zend/Loader.php"; Zend_Loader::registerAutoload(); // retrieve the token from the url // if the token doesn't exist, set a class containing only get_token() $token = optional_param('token', null, PARAM_ALPHANUM); ///this is a hack, because there is a bug in Zend framework (http://framework.zend.com/issues/browse/ZF-5736) if (empty($token)) { $relativepath = get_file_argument(); $args = explode('/', trim($relativepath, '/')); if (count($args) == 2) { $token = (int) $args[0]; $classpath = $args[1]; } } if (empty($token)) { if (isset($_GET['wsdl'])) { $autodiscover = new Zend_Soap_AutoDiscover(); /* $autodiscover->setComplexTypeStrategy('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex'); $autodiscover->setOperationBodyStyle( array('use' => 'literal', 'namespace' => $CFG->wwwroot) ); $autodiscover->setBindingStyle( array('style' => 'rpc') ); */ $autodiscover->setClass('ws_authentication'); $autodiscover->handle(); } else { $soap = new Zend_Soap_Server($CFG->wwwroot . "/webservice/soap/server.php?wsdl"); // this current file here $soap->registerFaultException('moodle_exception'); $soap->setClass('ws_authentication'); $soap->handle(); } } else { // if token exist, do the authentication here /// TODO: following function will need to be modified $user = webservice_lib::mock_check_token($token); if (empty($user)) { throw new moodle_exception('wrongidentification'); } else { /// TODO: probably change this global $USER; $USER = $user; } //retrieve the api name if (empty($classpath)) { $classpath = optional_param('classpath', null, PARAM_ALPHANUM); } require_once dirname(__FILE__) . '/../../' . $classpath . '/external.php'; /// run the server if (isset($_GET['wsdl'])) { $autodiscover = new Zend_Soap_AutoDiscover(); //this is a hack, because there is a bug in Zend framework (http://framework.zend.com/issues/browse/ZF-5736) $autodiscover->setUri($CFG->wwwroot . "/webservice/soap/server.php/" . $token . "/" . $classpath); $autodiscover->setClass($classpath . "_external"); $autodiscover->handle(); } else { $soap = new Zend_Soap_Server($CFG->wwwroot . "/webservice/soap/server.php?token=" . $token . "&classpath=" . $classpath . "&wsdl"); // this current file here $soap->setClass($classpath . "_external"); $soap->registerFaultException('moodle_exception'); $soap->handle(); } } }
public function testLoaderRegisterAutoloadInvalidClass() { if (!function_exists('spl_autoload_register')) { $this->markTestSkipped("spl_autoload() not installed on this PHP installation"); } try { Zend_Loader::registerAutoload('stdClass'); $this->fail('registerAutoload should fail without spl_autoload'); } catch (Exception $e) { $this->assertEquals('The class "stdClass" does not have an autoload() method', $e->getMessage()); } }
<?php define('BASE', dirname(dirname(dirname(dirname(__FILE__))))); ini_set('include_path', '/usr/share/php5/ZendFramework/library' . PATH_SEPARATOR . BASE . DIRECTORY_SEPARATOR . 'lib'); require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); $config = new Zend_Config_Ini(BASE . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'config.ini', 'live'); $db = Zend_Db::factory($config->db->adapter, $config->db->conn->toArray()); $server = new App_Chat_Server(new Room(), new Message()); $server->addRoom('test'); $server->addRoom('room2'); $server->handle();
/** * Initiates the object * @access public **/ public function __construct() { Zend_Loader::registerAutoload(); }