本文整理汇总了PHP中Dispatcher类的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher类的具体用法?PHP Dispatcher怎么用?PHP Dispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _main_
function _main_()
{
$ph = new PluginHandler();
$ph->register(new MyPlugin());
$sd = new Dispatcher($ph);
$sd->dispatch();
}
示例2: __autoload
function __autoload($className)
{
$dispatcher = new Dispatcher($className);
if (class_exists($className)) {
return;
}
if ($dispatcher->isBom()) {
require_once Configuration::getModelBomPath() . $className . '.php';
}
if ($dispatcher->isDao()) {
require_once Configuration::getModelDaoPath() . $className . '.php';
}
if ($dispatcher->isCoreInterface()) {
require_once Configuration::getInterfacePath() . $className . ".interface.php";
}
if ($dispatcher->isCoreController()) {
require_once Configuration::getControllersPath() . $className . ".php";
}
if ($dispatcher->isCoreBom()) {
require_once Configuration::getBusinessObjectModelsPath() . $className . ".php";
}
if ($dispatcher->isCoreDao()) {
require_once Configuration::getDatabaseAccessObjectPath() . $className . '.php';
}
if ($dispatcher->isCoreConstant()) {
require_once Configuration::getConstantsPath() . $className . ".constants.php";
}
if ($dispatcher->isCoreHelper()) {
require_once Configuration::getHelpersPath() . $className . ".helper.php";
}
if ($dispatcher->isCoreAbstract()) {
require_once Configuration::getAbstractPath() . $className . '.abstract.php';
}
}
示例3: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new Controller();
$dispatcher = new Dispatcher(new View());
$dispatcher->setBootstrap(new Bootstrap());
$this->object->setParams(array('dispatcher' => $dispatcher));
}
示例4: getAjaxTemplate
private function getAjaxTemplate()
{
foreach ($this->vars->isPost() as $key => $value) {
$data[$key] = $value;
}
$dispatcher = new Dispatcher();
$controller = $dispatcher->setController($data);
// Assign variables for the template
if ($controller['vars']) {
foreach ($controller['vars'] as $key => $value) {
$this->smarty->assign($key, $value);
}
}
if (isset($data['response'])) {
if ($data['response'] == 'html') {
return array('response' => 'html', 'data' => $dispatcher->loadTemplate());
} elseif ($data['response'] == 'json') {
return array('response' => 'json', 'data' => json_encode($controller['vars']));
} else {
throw new Exception('Ajax dataType must be html or json');
}
} else {
throw new Exception('response data must be given');
}
}
示例5: testServiceDispatchingUriRawUrlWithoutQueryParam
/**
* If RequestURI is proper URI and does not contain QueryParam then it will return proper o/p
*/
function testServiceDispatchingUriRawUrlWithoutQueryParam()
{
$_SERVER[ODataConstants::HTTPREQUEST_HEADER_METHOD] = ODataConstants::HTTP_METHOD_GET;
$_SERVER[ODataConstants::HTTPREQUEST_HEADER_PROTOCOL] = ODataConstants::HTTPREQUEST_HEADER_PROTOCOL_HTTP;
$_SERVER[ODataConstants::HTTPREQUEST_HEADER_HOST] = "localhost:8086";
$_SERVER[ODataConstants::HTTPREQUEST_HEADER_URI] = "/NorthWind.svc/Customers";
$_SERVER[ODataConstants::HTTPREQUEST_HEADER_QUERY_STRING] = null;
try {
$exceptionThrown = false;
$dispatcher = new Dispatcher();
//Service dispatched
$dispatcher->dispatch();
$contents = ob_get_contents();
ob_end_clean();
$this->assertContains("<feed xml:base=\"http://localhost:8086/NorthWind.svc", $contents);
$this->assertContains("<id>http://localhost:8086/NorthWind.svc/Customers</id>", $contents);
$absoluteUri = $dispatcher->getHost()->getAbsoluteRequestUriAsString();
$this->assertEquals("http://localhost:8086/NorthWind.svc/Customers", $absoluteUri);
$rawUrl = $dispatcher->getHost()->getWebOperationContext()->IncomingRequest()->getRawUrl();
$this->assertEquals("http://localhost:8086/NorthWind.svc/Customers", $rawUrl);
} catch (\Exception $exception) {
if (ob_get_length()) {
ob_end_clean();
}
$exceptionThrown = true;
$this->fail('Without Query Params - An unexpected exception has been thrown:' . $exception->getMessage());
}
if (!$exceptionThrown) {
$this->assertTrue(TRUE);
}
$dispatcher->getHost()->getWebOperationContext()->resetWebContextInternal();
}
示例6: setSail
/**
* T' the high seas! Garrr!
*/
public function setSail()
{
$request = new Request($_GET, $_POST, $_COOKIE, $_SERVER);
$router = new Router($request);
$response = new Response();
$dispatcher = new Dispatcher($router->dispatch(), $response);
$dispatcher->fireCannons();
}
示例7: testDispatchNotFoundRoute
public function testDispatchNotFoundRoute()
{
$dispatcher = new Dispatcher($this->router);
$response = $dispatcher->dispatch('GET', '/not-found');
assertThat($response, is(anInstanceOf('Rootr\\Response')));
assertThat($this->readAttribute($response, 'status'), is(equalTo(404)));
assertThat($this->readAttribute($response, 'body'), is(equalTo('Not Found')));
}
示例8: _dispatch
/**
* Redirects user to action in application with validated response data available as POST data retrievable at
* $this->request->data` at your app's controller.
*
* @param string $url Url in application to dispatch to
* @param array $data A list with post data
* @return void
*/
protected function _dispatch($url, $data)
{
$CakeRequest = new CakeRequest($url);
$CakeRequest->data = $data;
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch($CakeRequest, new CakeResponse());
$this->_stop();
}
示例9: __construct
public function __construct(Dispatcher $dispatcher, $fd, $what, $arg = null)
{
$this->dispatcher = $dispatcher;
$this->base = $dispatcher->getBase();
$this->fd = $fd;
$this->what = $what;
$this->argument = $arg;
$this->callback = [$this->dispatcher, Dispatcher::FORWARD_METHOD_NAME];
}
示例10: dispatch
/**
* @desc Redirect the request to the right controller using the url controller mappes list
* @param UrlControllerMapper[] $url_controller_mappers the url controllers mapper list
*/
public static function dispatch($url_controller_mappers)
{
try {
$dispatcher = new Dispatcher($url_controller_mappers);
$dispatcher->dispatch();
} catch (NoUrlMatchException $ex) {
self::handle_dispatch_exception($ex);
}
}
示例11: testRemoveListener
/**
*/
public function testRemoveListener()
{
$eventName = 'test';
$dispatcher = new Dispatcher();
$listener = new Listener($eventName);
$dispatcher->addListener($eventName, $listener);
$dispatcher->removeListener($eventName, $listener);
$this->assertEmpty($dispatcher->getListeners());
}
示例12: beforeRedirect
/**
* Intercept redirect and render amf response
*
* @param object $controller
* @return void
*/
function beforeRedirect(&$controller, $url, $status = null, $exit = true)
{
if ($controller->isAmf && $this->autoRedirect) {
if (is_array($url)) {
$url = Router::url($url);
}
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch($url);
if ($exit) {
exit;
}
}
}
示例13: dispatch
public static function dispatch(Request $request = null, Response $response = null)
{
if ($request === null) {
$request = new Request();
}
if ($response === null) {
$response = new Response();
}
$app = self::instance();
$app->setRequest($request);
$dispatcher = new Dispatcher(APP_CONTROLLERS_DIR);
$dispatcher->dispatch($request, $response);
$response->send();
}
示例14: testDispatching
public function testDispatching()
{
$dispatcher = new Dispatcher(['index', 'blog', 'projects', '_drafts/blog']);
$dispatcher->map('blog', 'bloge');
$dispatcher->alias('projects', 'projectos');
$dispatcher->ignore('_drafts/blog');
$this->assertEquals('blog', $dispatcher->dispatch('bloge'));
$this->assertEquals('projects', $dispatcher->dispatch('projectos'));
$this->assertEquals('projects', $dispatcher->dispatch('projects'));
$this->assertEquals('', $dispatcher->dispatch('_drafts/blog'));
$this->assertEquals('foobar', $dispatcher->dispatch('foobar'));
}
示例15: _prepareHook
protected function _prepareHook($params)
{
$languages = Language::getLanguages(true, $this->context->shop->id);
if (!count($languages)) {
return false;
}
$link = new Link();
if ((int) Configuration::get('PS_REWRITING_SETTINGS')) {
$default_rewrite = array();
if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int) Tools::getValue('id_product'))) {
$rewrite_infos = Product::getUrlRewriteInformations((int) $id_product);
foreach ($rewrite_infos as $infos) {
$default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']);
}
}
if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int) Tools::getValue('id_category'))) {
$rewrite_infos = Category::getUrlRewriteInformations((int) $id_category);
foreach ($rewrite_infos as $infos) {
$default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']);
}
}
if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int) Tools::getValue('id_cms')) || ($id_cms_category = (int) Tools::getValue('id_cms_category')))) {
$rewrite_infos = isset($id_cms) && !isset($id_cms_category) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category);
foreach ($rewrite_infos as $infos) {
$arr_link = isset($id_cms) && !isset($id_cms_category) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']);
$default_rewrite[$infos['id_lang']] = $arr_link;
}
}
$this->smarty->assign('lang_rewrite_urls', $default_rewrite);
}
return true;
}