本文整理汇总了PHP中Zend_Controller_Router_Route类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Controller_Router_Route类的具体用法?PHP Zend_Controller_Router_Route怎么用?PHP Zend_Controller_Router_Route使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Controller_Router_Route类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: routeStartup
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
if (!$this->_issession) {
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
if ($this->_domain) {
$doms = $this->_model->fetchPairs('id', 'domain');
if ($doms) {
foreach ($doms as $k => $el) {
$doms[$k] = @$el[0] ? explode(' ', $el) : array();
}
}
$lang = $request->getParam('lang');
if ($lang) {
$this->_session->lang = $this->_model->fetchOne('id', array('`stitle` = ?' => $lang));
} else {
if ($doms) {
foreach ($doms as $k => $el) {
if (in_array($_SERVER['HTTP_HOST'], $el)) {
$this->_session->lang = $k;
break;
}
}
}
}
$this->_lang = $this->_model->fetchRow(null, '(`id` = ' . (int) $this->_session->lang . ') DESC, (`default` = 1) DESC');
if ($this->_lang) {
$this->_lang = new Zkernel_View_Data($this->_lang);
}
$this->_lang->_default = $this->getDefault();
$this->_lang->_ids = $this->_model->fetchIds();
$this->_lang->_doms = $doms;
} else {
$routes = $router->getRoutes();
$router->removeDefaultRoutes();
if ($routes) {
foreach ($routes as $k => $el) {
$router->removeRoute($k);
}
}
$langRoute = new Zend_Controller_Router_Route(':lang', array('lang' => $this->getDefault()->stitle));
$router->addRoute('default', $langRoute->chain(new Zend_Controller_Router_Route_Module(array(), $front->getDispatcher(), $front->getRequest())));
$router->addRoute('lang', $langRoute);
if ($routes) {
foreach ($routes as $k => $el) {
$router->addRoute($k, $k == 'fu' || $k == 'minify' ? $el : $langRoute->chain($el));
}
}
}
}
$this->save();
}
示例2: match
/**
* Attempt to match the current request URL
* If a match is found, instantiate a new ImboClient
*
* @see Zend_Controller_Router_Route::match()
*/
public function match($path, $partial = false)
{
$match = parent::match($path, $partial);
$config = array();
$instance = false;
$imgUrl = '';
if ($match) {
$instance = $match['instance'];
// Check if the passed instance exists
if (!isset($this->instances[$instance])) {
throw new Zend_Controller_Router_Exception('Instance "' . $instance . '" does not exist in configuration', 404);
}
// If this is not a sub-action, check if this is an XMLHttpRequest
if ($match['controller'] != 'instance' && (!isset($_SERVER['X_REQUESTED_WITH']) || $_SERVER['X_REQUESTED_WITH'] != 'XMLHttpRequest')) {
$match['controller'] = 'instance';
$match['action'] = 'index';
}
// Create an imbo client for the given instance and make it available in request
$config = $this->instances[$instance];
$match['imboClient'] = new ImboClient\Client($config['host'], $config['pubkey'], $config['privkey']);
$imgUrl = $match['imboClient']->getImagesUrl();
}
// Set active instance name to view so we may use it in frontend
$frontController = Zend_Controller_Front::getInstance();
$view = $frontController->getParam('bootstrap')->getResource('view');
$view->activeInstance = $instance;
$view->imagesUrl = $imgUrl;
$view->maxUploadSize = $this->getMaxUploadSize($config);
return $match;
}
示例3: routeShutdown
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$language = $request->getParam("language", Zend_Registry::get('Zend_Locale')->getLanguage());
$locale = new Zend_Locale($language);
Zend_Registry::get('Zend_Locale')->setLocale($locale);
$translate = Zend_Registry::get('Zend_Translate');
$translate->getAdapter()->setLocale(Zend_Registry::get('Zend_Locale'));
Zend_Controller_Router_Route::setDefaultTranslator($translate);
}
示例4: init
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Controller_Router_Rewrite
*/
public function init()
{
if (null === $this->_router) {
$router = $this->getRouter();
// returns $this->_router
$router->addConfig($this->_getConfig());
// add locale chain if using translate
if ($this->getBootstrap()->hasPluginResource('Translate')) {
$locale = new Zend_Controller_Router_Route(':locale', array(), array('locale' => '^[a-z]{2}$'));
$router->addDefaultRoutes();
foreach ($router->getRoutes() as $name => $route) {
//rename existing routes
$router->removeRoute($name)->addRoute($name . 'Default', $route)->addRoute($name, $locale->chain($route));
}
}
}
return $this->_router;
}
示例5: _initRoutes
/**
* Routes initialization
*
* @return Zend_Controller_Router
*/
protected function _initRoutes()
{
$this->bootstrapOptions();
$router = new \Zend_Controller_Router_Rewrite();
foreach (\NS\Service\AbstractService::getConfig() as $module => $config) {
if ($config->routes) {
foreach ($config->routes as $r => $routeConfig) {
$router->addRoute($module . '_' . $r, \Zend_Controller_Router_Route::getInstance($routeConfig));
}
}
}
\Zend_Controller_Front::getInstance()->setRouter($router);
return $router;
}
示例6: testEscapedSpecialCharsWithTranslation
public function testEscapedSpecialCharsWithTranslation()
{
$route = new Zend_Controller_Router_Route('::foo/@@bar/:@myvar');
$path = $route->assemble(array('myvar' => 'foo'));
$this->assertEquals($path, ':foo/@bar/en_foo');
$values = $route->match(':foo/@bar/en_foo');
$this->assertEquals($values['myvar'], 'foo');
}
示例7: testAssembleWithRemovedDefaults
public function testAssembleWithRemovedDefaults() // Test for ZF-1197
{
$route = new Zend_Controller_Router_Route(':controller/:action/*', array('controller' => 'index', 'action' => 'index'));
$url = $route->assemble(array('id' => 3));
$this->assertSame('index/index/id/3', $url);
$url = $route->assemble(array('action' => 'test'));
$this->assertSame('index/test', $url);
$url = $route->assemble(array('action' => 'test', 'id' => 3));
$this->assertSame('index/test/id/3', $url);
$url = $route->assemble(array('controller' => 'test'));
$this->assertSame('test', $url);
$url = $route->assemble(array('controller' => 'test', 'action' => 'test'));
$this->assertSame('test/test', $url);
$url = $route->assemble(array('controller' => 'test', 'id' => 3));
$this->assertSame('test/index/id/3', $url);
$url = $route->assemble(array());
$this->assertSame('', $url);
$route->match('ctrl');
$url = $route->assemble(array('id' => 3));
$this->assertSame('ctrl/index/id/3', $url);
$url = $route->assemble(array('action' => 'test'));
$this->assertSame('ctrl/test', $url);
$url = $route->assemble();
$this->assertSame('ctrl', $url);
$route->match('index');
$url = $route->assemble();
$this->assertSame('', $url);
}
示例8: _initTranslate
/**
* Initializes translator
*
* @return Zend_Translate_Adapter
*/
public function _initTranslate()
{
$log = new Zend_Log();
if (APPLICATION_ENV == 'development') {
$log = new Zend_Log();
$log->addWriter(new Zend_Log_Writer_Firebug());
//$log->addWriter(new Zend_Log_Writer_Stream(APPLICATION_PATH . '/temporary/log/translate.log'));
} else {
$log->addWriter(new Zend_Log_Writer_Null());
}
$params['log'] = $log;
// Create the object and add a language
$translate = new Zend_Translate('Array', APPLICATION_PATH . '/languages/vi/vi.php', 'vi_VN');
// Add another translation
$translate->addTranslation(APPLICATION_PATH . '/languages/en/en.php', 'en_US');
// Set nb_NO as default translation
$translate->setLocale('vi_VN');
Zend_Registry::set('Zend_Translate', $translate);
Zend_Validate_Abstract::setDefaultTranslator($translate);
Zend_Form::setDefaultTranslator($translate);
Zend_Controller_Router_Route::setDefaultTranslator($translate);
return $translate;
}
示例9: Zend_Translate
<?php
$conf = Zend_Registry::get("conf");
try {
// Translation
$translateUrl = new Zend_Translate('gettext', APPLICATION_DIRECTORY . '/Joobsbox/Languages/' . $locale . '/LC_MESSAGES/url.mo', $locale, array('disableNotices' => true));
} catch (Exception $e) {
$translateUrl = new Zend_Translate('gettext', APPLICATION_DIRECTORY . '/Joobsbox/Languages/en/LC_MESSAGES/url.mo', 'en');
}
Zend_Registry::set("Joobsbox_Translate_URL", $translateUrl);
Zend_Controller_Router_Route::setDefaultTranslator($translateUrl);
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$rssRoute = new Zend_Controller_Router_Route('rss/@category/:category', array('controller' => 'rss', 'action' => 'index'));
$mainRoute = new Zend_Controller_Router_Route(':@controller/:@action/*', array('controller' => 'index', 'action' => 'index'));
$mainRoute2 = new Zend_Controller_Router_Route('index.php/:@controller/:@action/*', array('controller' => 'index', 'action' => 'index'));
$router->addRoute("main", $mainRoute);
$router->addRoute("main2", $mainRoute2);
$router->addRoute("rss", $rssRoute);
$mainRoute->assemble(array());
$mainRoute->assemble(array());
$mainRoute2->assemble(array());
$mainRoute2->assemble(array());
$front->setRouter($router);
示例10: test_RESTfulApp_route_chaining_urlencodedWithPlusSymbol
/**
* @group ZF-10964
*/
public function test_RESTfulApp_route_chaining_urlencodedWithPlusSymbol()
{
$request = $this->_buildRequest('GET', '/api/user/email%2Btest%40example.com');
$this->_front->setRequest($request);
$router = $this->_front->getRouter();
$router->removeDefaultRoutes();
$nonRESTRoute = new Zend_Controller_Router_Route('api');
$RESTRoute = new Zend_Rest_Route($this->_front);
$router->addRoute("api", $nonRESTRoute->chain($RESTRoute));
$routedRequest = $router->route($request);
$this->assertEquals("default", $routedRequest->getParam("module"));
$this->assertEquals("user", $routedRequest->getParam("controller"));
$this->assertEquals("get", $routedRequest->getParam("action"));
$this->assertEquals("email+test@example.com", $routedRequest->getParam("id"));
}
示例11: _initTranslate
//.........这里部分代码省略.........
foreach( $it as $item ) {
if( $item->isDot() || !$item->isDir() ) {
continue;
}
$name = $item->getBasename();
if( !Zend_Locale::isLocale($name) ) {
continue;
}
$languages[] = $name;
}
*/
// If in development, log untranslated messages
$params = array('scan' => Zend_Translate_Adapter::LOCALE_DIRECTORY, 'logUntranslated' => true);
$log = new Zend_Log();
if (APPLICATION_ENV == 'development') {
$log = new Zend_Log();
$log->addWriter(new Zend_Log_Writer_Firebug());
$log->addWriter(new Zend_Log_Writer_Stream(APPLICATION_PATH . '/temporary/log/translate.log'));
} else {
$log->addWriter(new Zend_Log_Writer_Null());
}
$params['log'] = $log;
// Check Locale
$locale = Zend_Locale::findLocale();
// Make Sure Language Folder Exist
$languageFolder = is_dir(APPLICATION_PATH . '/application/languages/' . $locale);
if ($languageFolder === false) {
$locale = substr($locale, 0, 2);
$languageFolder = is_dir(APPLICATION_PATH . '/application/languages/' . $locale);
if ($languageFolder == false) {
$locale = 'en';
}
}
// Check which Translation Adapter has been selected
$db = Engine_Db_Table::getDefaultAdapter();
$translationAdapter = $db->select()->from('engine4_core_settings', 'value')->where('`name` = ?', 'core.translate.adapter')->query()->fetchColumn();
// If adapter is 'array', Make sure array files exist
/*
if( $translationAdapter == 'array'){
// Check if Language File Exists
if( !file_exists(APPLICATION_PATH . '/application/languages/' . $locale . '/' . $locale . '.php')){
//echo 'Locale does not exist ' . APPLICATION_PATH . '/application/languages/' . $locale . '/' . $locale . '_array.php<br />';
// Try looking elsewhere
$newLocale = substr($locale, 0, 2);
//echo 'Attempting to Look for ' . $newLocale . '<br />';
if( file_exists(APPLICATION_PATH . '/application/languages/' . $newLocale . '/' . $newLocale . '.php')){
$locale = $newLocale;
//echo 'New Locale Found ' . APPLICATION_PATH . '/application/languages/' . $newLocale . '/' . $newLocale . '_array.php<br />';
} else { $translationAdapter = 'csv'; $locale = 'en'; }
}
}
*/
// Use Array Translation Adapter, Loop through all Availible Translations
if ($translationAdapter == 'array') {
// Find all Valid Language Arrays
// Check For Array Files
$languagePath = APPLICATION_PATH . '/application/languages';
// Get List of Folders
$languageFolders = array_filter(glob($languagePath . DIRECTORY_SEPARATOR . '*'), 'is_dir');
// Look inside Folders for PHP array
$locale_array = array();
foreach ($languageFolders as $folder) {
// Get Locale code
$locale_code = str_replace($languagePath . DIRECTORY_SEPARATOR, "", $folder);
$locale_array[] = $locale_code;
if (!file_exists($folder . DIRECTORY_SEPARATOR . $locale_code . '.php')) {
// If Array files do not exist, switch to CSV
$translationAdapter = 'csv';
}
}
$language_count = count($locale_array);
// Add the First One
$translate = new Zend_Translate(array('adapter' => 'array', 'content' => $languagePath . DIRECTORY_SEPARATOR . $locale_array[0] . DIRECTORY_SEPARATOR . $locale_array[0] . '.php', 'locale' => $locale_array[0]));
if ($language_count > 1) {
for ($i = 1; $i < $language_count; $i++) {
$translate->addTranslation(array('content' => $languagePath . DIRECTORY_SEPARATOR . $locale_array[$i] . DIRECTORY_SEPARATOR . $locale_array[$i] . '.php', 'locale' => $locale_array[$i]));
}
}
/*
if( $language_count > 1) {
for( $i = 1; $i < $language_count; $i++ ) {
$translate->addTranslation(
array(
'content' => $languageFolders[$i] . DIRECTORY_SEPARATOR . $locale_array[$i] . '.php',
'locale' => $locale_array[$i] )
);
echo $locale_array[$i] . ' Translation Added<br />';
}
}
* */
} else {
$translate = new Zend_Translate('Csv', APPLICATION_PATH . '/application/languages', null, $params);
}
Zend_Registry::set('Zend_Translate', $translate);
Zend_Validate_Abstract::setDefaultTranslator($translate);
Zend_Form::setDefaultTranslator($translate);
Zend_Controller_Router_Route::setDefaultTranslator($translate);
return $translate;
}
示例12: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($request, $partial = false)
{
if (!$request instanceof \Zend_Controller_Request_Http) {
throw new \Zend_Controller_Router_Exception("Route needs a http request");
}
$return = parent::match($request->getPathInfo(), $partial);
if (!$return) {
return $return;
}
if (!($token = $return[$this->_tokenVariable])) {
throw new \Zend_Controller_Router_Exception("Token not defined", 400);
}
if (!($tokenData = \Download\Service\DownloadTokenService::getInstance()->popToken($token))) {
throw new \Zend_Controller_Router_Exception("Token does not exist or has expired", 400);
}
$return = array_merge($return, $tokenData->exportData());
$return['downloadToken'] = $tokenData;
$return['module'] = 'download';
//Data defined inside token
$return['controller'] = $tokenData->controller;
$return['action'] = $tokenData->action;
if (is_array($tokenData->params)) {
$return += $tokenData->params;
}
return $return;
}
示例13: __construct
public function __construct()
{
/* Informações */
$route = $this->getRoute();
$defaults = $this->getDefaults();
/* Construtor */
parent::__construct($route, $defaults);
}
示例14: assemble
public function assemble($data = array(), $reset = false, $encode = false)
{
$return = parent::assemble($data, $reset, $encode);
if ($this->_representationParam !== null) {
if ($return && isset($data[$this->_representationParam])) {
$return .= '.' . $data[$this->_representationParam];
}
}
return $return;
}
示例15: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path, $partial = false)
{
$return = parent::match($path, $partial);
// add the RESTful action mapping
if ($return) {
//add the data that is a wildcard to the end of the return array
$path = trim($path, self::URI_DELIMITER);
$this->_route = trim($this->_route, self::URI_DELIMITER);
if ($path != '') {
$elementsPath = explode(self::URI_DELIMITER, $path);
}
if ($this->_route != '') {
$elementsRoute = explode(self::URI_DELIMITER, $this->_route);
}
//and now get rid of all entries that are not a wildcard. when we have done that,
//we have what we wanted...
foreach ($elementsRoute as $key => $value) {
if ($value !== "*") {
array_shift($elementsPath);
} else {
break;
}
}
$i = 0;
foreach ($elementsPath as $value) {
$return['wild' . $i] = $value;
$i++;
}
//reset things
$request = $this->_front->getRequest();
$params = $request->getParams();
$path = $elementsPath;
//Store path count for method mapping
$pathElementCount = count($path);
// Determine Action
$requestMethod = strtolower($request->getMethod());
if ($requestMethod != 'get') {
if ($request->getParam('_method')) {
$return[$this->_actionKey] = strtolower($request->getParam('_method'));
} elseif ($request->getHeader('X-HTTP-Method-Override')) {
$return[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
} else {
$return[$this->_actionKey] = $requestMethod;
}
} else {
// this is only an index call, if no options are acutally provided
if ($pathElementCount > 0) {
$return[$this->_actionKey] = 'get';
} else {
$return[$this->_actionKey] = 'index';
}
}
}
return $return;
}