當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EventDispatcher::addSubscriber方法代碼示例

本文整理匯總了PHP中Symfony\Component\EventDispatcher\EventDispatcher::addSubscriber方法的典型用法代碼示例。如果您正苦於以下問題:PHP EventDispatcher::addSubscriber方法的具體用法?PHP EventDispatcher::addSubscriber怎麽用?PHP EventDispatcher::addSubscriber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\EventDispatcher\EventDispatcher的用法示例。


在下文中一共展示了EventDispatcher::addSubscriber方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: shouldCustomizeParameterNames

 /**
  * @test
  */
 function shouldCustomizeParameterNames()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new MockPaginationSubscriber());
     // pagination view
     $dispatcher->addSubscriber(new ArraySubscriber());
     $p = new Paginator($dispatcher);
     $items = array('first', 'second');
     $view = $p->paginate($items, 1, 10);
     // test default names first
     $this->assertEquals('page', $view->getPaginatorOption('pageParameterName'));
     $this->assertEquals('sort', $view->getPaginatorOption('sortFieldParameterName'));
     $this->assertEquals('direction', $view->getPaginatorOption('sortDirectionParameterName'));
     $this->assertTrue($view->getPaginatorOption('distinct'));
     $this->assertNull($view->getPaginatorOption('sortFieldWhitelist'));
     // now customize
     $options = array('pageParameterName' => 'p', 'sortFieldParameterName' => 's', 'sortDirectionParameterName' => 'd', 'distinct' => false, 'sortFieldWhitelist' => array('a.f', 'a.d'));
     $view = $p->paginate($items, 1, 10, $options);
     $this->assertEquals('p', $view->getPaginatorOption('pageParameterName'));
     $this->assertEquals('s', $view->getPaginatorOption('sortFieldParameterName'));
     $this->assertEquals('d', $view->getPaginatorOption('sortDirectionParameterName'));
     $this->assertFalse($view->getPaginatorOption('distinct'));
     $this->assertEquals(array('a.f', 'a.d'), $view->getPaginatorOption('sortFieldWhitelist'));
     // change default paginator options
     $p->setDefaultPaginatorOptions(array('pageParameterName' => 'pg', 'sortFieldParameterName' => 'srt', 'sortDirectionParameterName' => 'dir'));
     $view = $p->paginate($items, 1, 10);
     $this->assertEquals('pg', $view->getPaginatorOption('pageParameterName'));
     $this->assertEquals('srt', $view->getPaginatorOption('sortFieldParameterName'));
     $this->assertEquals('dir', $view->getPaginatorOption('sortDirectionParameterName'));
     $this->assertTrue($view->getPaginatorOption('distinct'));
 }
開發者ID:Dren-x,項目名稱:mobit,代碼行數:34,代碼來源:AbstractPaginationTest.php

示例2: registerSubscribers

 public function registerSubscribers()
 {
     // required
     $this->dispatcher->addSubscriber(new Subscriber\GracefulTermination());
     $this->dispatcher->addSubscriber(new Subscriber\ErrorHandler());
     $this->dispatcher->addSubscriber(new Subscriber\Bootstrap());
     $this->dispatcher->addSubscriber(new Subscriber\Module());
     $this->dispatcher->addSubscriber(new Subscriber\BeforeAfterTest());
     // optional
     if (!$this->options['no-rebuild']) {
         $this->dispatcher->addSubscriber(new Subscriber\AutoRebuild());
     }
     if (!$this->options['silent']) {
         $this->dispatcher->addSubscriber(new Subscriber\Console($this->options));
     }
     if ($this->options['fail-fast']) {
         $this->dispatcher->addSubscriber(new Subscriber\FailFast());
     }
     if ($this->options['coverage']) {
         $this->dispatcher->addSubscriber(new Coverage\Subscriber\Local($this->options));
         $this->dispatcher->addSubscriber(new Coverage\Subscriber\LocalServer($this->options));
         $this->dispatcher->addSubscriber(new Coverage\Subscriber\RemoteServer($this->options));
         $this->dispatcher->addSubscriber(new Coverage\Subscriber\Printer($this->options));
     }
     // extensions
     foreach ($this->extensions as $subscriber) {
         $this->dispatcher->addSubscriber($subscriber);
     }
 }
開發者ID:hitechdk,項目名稱:Codeception,代碼行數:29,代碼來源:Codecept.php

示例3: getEventDispatcher

 /**
  * @return EventDispatcher
  */
 protected function getEventDispatcher()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new EventListener\ErrorLogSubscriber());
     $dispatcher->addSubscriber(new EventListener\FailureSubscriber($this->getQueueFactory()));
     return $dispatcher;
 }
開發者ID:plispe,項目名稱:kiss,代碼行數:10,代碼來源:Bernard.php

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $codeLocation = $input->getArgument('code-location');
     $codeDestination = $input->getOption('code-destination');
     $createNamespace = $input->getOption('create-namespace');
     $offset = $input->getOption('offset');
     $length = $input->getOption('length');
     $classyfile = new ClassyFile();
     $dispatcher = new EventDispatcher();
     if ($input->getOption('constants-to-upper')) {
         $plugin = new ConstantNamesToUpper();
         $dispatcher->addSubscriber($plugin);
     }
     if ($input->getOption('psr-fix')) {
         $plugin = new PhpCsFixer($input, $output);
         $dispatcher->addSubscriber($plugin);
     }
     if ($input->getOption('remove-top-comment')) {
         $classyfile->setTemplate(new BasicClassTemplate(''), 'getTemplate');
     }
     $classyfile->setEventDispatcher($dispatcher);
     if ($createNamespace) {
         $classyfile->generateClassFiles($codeDestination, $codeLocation, $offset, $length);
     } else {
         $classyfile->generateClassFiles($codeDestination, $codeLocation);
     }
 }
開發者ID:onema,項目名稱:classyfile,代碼行數:27,代碼來源:GenerateClassesFromFileCommand.php

示例5: shouldSortSimpleDoctrineQuery

 /**
  * @test
  */
 function shouldSortSimpleDoctrineQuery()
 {
     $em = $this->getMockSqliteEntityManager();
     $this->populate($em);
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new PaginationSubscriber());
     $dispatcher->addSubscriber(new Sortable());
     $p = new Paginator($dispatcher);
     $_GET['sort'] = 'a.title';
     $_GET['direction'] = 'asc';
     $this->startQueryLog();
     $query = $this->em->createQuery('SELECT a FROM Test\\Fixture\\Entity\\Article a');
     $view = $p->paginate($query, 1, 10);
     $items = $view->getItems();
     $this->assertEquals(4, count($items));
     $this->assertEquals('autumn', $items[0]->getTitle());
     $this->assertEquals('spring', $items[1]->getTitle());
     $this->assertEquals('summer', $items[2]->getTitle());
     $this->assertEquals('winter', $items[3]->getTitle());
     $_GET['direction'] = 'desc';
     $view = $p->paginate($query, 1, 10);
     $items = $view->getItems();
     $this->assertEquals(4, count($items));
     $this->assertEquals('winter', $items[0]->getTitle());
     $this->assertEquals('summer', $items[1]->getTitle());
     $this->assertEquals('spring', $items[2]->getTitle());
     $this->assertEquals('autumn', $items[3]->getTitle());
     $this->assertEquals(6, $this->queryAnalyzer->getNumExecutedQueries());
     $executed = $this->queryAnalyzer->getExecutedQueries();
     $this->assertEquals('SELECT DISTINCT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title ASC LIMIT 10 OFFSET 0', $executed[1]);
     $this->assertEquals('SELECT DISTINCT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title DESC LIMIT 10 OFFSET 0', $executed[4]);
 }
開發者ID:justus-alex,項目名稱:TaxiPrize,代碼行數:35,代碼來源:QueryTest.php

示例6: __construct

 public function __construct($name, array $params = [])
 {
     $app = $this;
     $locator = new FileLocator();
     $this->routesFileLoader = new YamlFileLoader($locator);
     $this['context'] = function () {
         return new RequestContext();
     };
     $this['matcher'] = function () {
         return new UrlMatcher($this['routes'], $this['context']);
     };
     $this['resolver'] = function () {
         return new ControllerResolver($this);
     };
     $this['dispatcher'] = function () use($app) {
         $dispatcher = new EventDispatcher();
         $dispatcher->addSubscriber(new RouterListener($app['matcher']));
         $dispatcher->addSubscriber(new ResponseListener($app['charset']));
         return $dispatcher;
     };
     $this['kernel'] = function () use($app) {
         return new HttpKernel($app['dispatcher'], $app['resolver']);
     };
     //        $this['request.http_port']  = 80;
     //        $this['request.https_port'] = 443;
     $this['charset'] = 'UTF-8';
     parent::__construct($name, null, $params);
     $this->setApp($this);
 }
開發者ID:php-go,項目名稱:php-go,代碼行數:29,代碼來源:Application.php

示例7: __construct

 public function __construct(EventSubscriberInterface $subscriber, MatcherInterface $matcher)
 {
     $this->proxied = $subscriber;
     $this->matcher = $matcher;
     $this->dispatcher = new EventDispatcher();
     $this->dispatcher->addSubscriber($subscriber);
 }
開發者ID:LastCallMedia,項目名稱:Crawler,代碼行數:7,代碼來源:MatchingProxy.php

示例8: get_event_dispatcher

function get_event_dispatcher()
{
    $dispatcher = new EventDispatcher();
    $dispatcher->addSubscriber(new EventListener\ErrorLogSubscriber());
    $dispatcher->addSubscriber(new EventListener\FailureSubscriber(get_queue_factory()));
    return $dispatcher;
}
開發者ID:acrobat,項目名稱:bernard,代碼行數:7,代碼來源:bootstrap.php

示例9: shouldSortSimpleDoctrineQuery

 /**
  * @test
  */
 function shouldSortSimpleDoctrineQuery()
 {
     $this->populate();
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new PaginationSubscriber());
     $dispatcher->addSubscriber(new Sortable());
     $p = new Paginator($dispatcher);
     $_GET['sort'] = 'title';
     $_GET['direction'] = 'asc';
     $qb = $this->dm->createQueryBuilder('Test\\Fixture\\Document\\Article');
     $query = $qb->getQuery();
     $view = $p->paginate($query, 1, 10);
     $items = array_values($view->getItems());
     $this->assertEquals(4, count($items));
     $this->assertEquals('autumn', $items[0]->getTitle());
     $this->assertEquals('spring', $items[1]->getTitle());
     $this->assertEquals('summer', $items[2]->getTitle());
     $this->assertEquals('winter', $items[3]->getTitle());
     $_GET['direction'] = 'desc';
     $view = $p->paginate($query, 1, 10);
     $items = array_values($view->getItems());
     $this->assertEquals(4, count($items));
     $this->assertEquals('winter', $items[0]->getTitle());
     $this->assertEquals('summer', $items[1]->getTitle());
     $this->assertEquals('spring', $items[2]->getTitle());
     $this->assertEquals('autumn', $items[3]->getTitle());
 }
開發者ID:Dren-x,項目名稱:mobit,代碼行數:30,代碼來源:QueryTest.php

示例10: getDispatcher

 public static function getDispatcher()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new RouterListener(new UrlMatcher(self::getRoutes(), new RequestContext())));
     $dispatcher->addSubscriber(new KernelExceptionSubscriber());
     return $dispatcher;
 }
開發者ID:Asmerok,項目名稱:UCCA,代碼行數:7,代碼來源:Application.php

示例11: it_converts_exception_to_json

 /** @test */
 public function it_converts_exception_to_json()
 {
     $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
     $resolver->expects($this->once())->method('getController')->will($this->returnValue(function () {
         throw new NotFoundHttpException();
     }));
     $resolver->expects($this->once())->method('getArguments')->will($this->returnValue([]));
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('error');
     $dispatcher = new EventDispatcher();
     $httpKernel = new HttpKernel($dispatcher, $resolver);
     $kernel = new KernelForTest('test', true);
     $kernel->boot();
     $kernel->getContainer()->set('http_kernel', $httpKernel);
     $dispatcher->addSubscriber(new RequestFormatNegotiationListener());
     $dispatcher->addSubscriber(new RequestFormatValidationListener());
     $dispatcher->addSubscriber(new ResponseConversionListener());
     $dispatcher->addSubscriber(new ExceptionConversionListener($logger));
     $request = Request::create('/exception', 'GET', [], [], [], ['HTTP_ACCEPT' => 'application/json']);
     $request->attributes->set('_format', 'json');
     $response = $kernel->handle($request)->prepare($request);
     $this->assertSame(404, $response->getStatusCode());
     $this->assertSame('application/vnd.error+json', $response->headers->get('Content-Type'));
     $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'Not Found']), $response->getContent());
 }
開發者ID:jsor,項目名稱:stack-hal,代碼行數:26,代碼來源:KernelTest.php

示例12: setUp

 public function setUp()
 {
     $this->requestStack = new RequestStack();
     $request = new Request();
     $this->requestStack->push($request);
     $this->session = new Session(new MockArraySessionStorage());
     $request->setSession($this->session);
     $this->dispatcher = new EventDispatcher();
     $translator = new Translator($this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface'));
     $token = new TokenProvider($this->requestStack, $translator, 'test');
     $this->dispatcher->addSubscriber(new \Thelia\Action\Cart($this->requestStack, $token));
     $this->session->setSessionCart(null);
     $request->setSession($this->session);
     /** @var \Thelia\Action\Cart  cartAction */
     $this->cartAction = new \Thelia\Action\Cart($this->requestStack, new TokenProvider($this->requestStack, $translator, 'baba au rhum'));
     $this->dispatcherNull = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', array(), array(), '', true, true, true, false);
     $this->dispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($type, $event) {
         if ($type == TheliaEvents::CART_RESTORE_CURRENT) {
             $this->cartAction->restoreCurrentCart($event, null, $this->dispatcher);
         } elseif ($type == TheliaEvents::CART_CREATE_NEW) {
             $this->cartAction->createEmptyCart($event, null, $this->dispatcher);
         }
     }));
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:25,代碼來源:SessionTest.php

示例13: testChangePermissionsForCommittedSqon

 /**
  * Verifies that permissions are changed.
  */
 public function testChangePermissionsForCommittedSqon()
 {
     chmod($this->path, 0644);
     $this->dispatcher->addSubscriber(new ChmodSubscriber(0755));
     $this->dispatcher->dispatch(AfterCommitEvent::NAME, new AfterCommitEvent($this->sqon));
     clearstatcache(true, $this->path);
     self::assertEquals('755', substr(sprintf('%o', fileperms($this->path)), -3, 3), 'The file permissions were not set.');
 }
開發者ID:sqon,項目名稱:sqon,代碼行數:11,代碼來源:ChmodSubscriberTest.php

示例14: setUp

 public function setUp()
 {
     $this->message = Message::create('lussuti.lus');
     $this->ed = new EventDispatcher();
     $this->output = $this->getMock('Symfony\\Component\\Console\\Output\\ConsoleOutputInterface');
     $subscriber = new ConsoleOutputSubscriber($this->output);
     $this->ed->addSubscriber($subscriber);
 }
開發者ID:pekkis,項目名稱:queue,代碼行數:8,代碼來源:ConsoleOutputSubscriberTest.php

示例15: installShouldCreateCacheDir

 /**
  * @test
  */
 public function installShouldCreateCacheDir()
 {
     $src = self::$fixturesDirectory . '/config';
     $configuration = $this->createConfig($src);
     $this->eventDispatcher->addSubscriber(new CacheCreateListener($this->bower));
     $this->bower->install($configuration);
     $this->assertFileExists($this->target . '/cache');
 }
開發者ID:boskee,項目名稱:SpBowerBundle,代碼行數:11,代碼來源:BowerFunctionalTest.php


注:本文中的Symfony\Component\EventDispatcher\EventDispatcher::addSubscriber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。