当前位置: 首页>>代码示例>>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;未经允许,请勿转载。