예제 #1
0
파일: Model.php 프로젝트: minwork/minwork
 public function __construct(DatabaseStorageInterface $storage, $id = null, $eventDispatcher = null)
 {
     $this->reset()->setStorage($storage)->setId($id)->setEventDispatcher($eventDispatcher ?? EventDispatcher::getGlobal());
 }
예제 #2
0
 public function __construct(DatabaseStorageInterface $storage, array $models, $eventDispatcher = null)
 {
     $this->reset()->setStorage($storage)->setModels($models)->setEventDispatcher($eventDispatcher ?? EventDispatcher::getGlobal());
 }
예제 #3
0
 public function __construct(string $name, bool $canQueue = true, bool $canRevert = false, EventDispatcherInterface $eventDispatcher = null)
 {
     $this->setName($name)->setCanQueue($canQueue)->setCanRevert($canRevert)->setEventDispatcher($eventDispatcher ?? EventDispatcher::getGlobal());
 }
예제 #4
0
 public function __construct(RouterInterface $router, EnvironmentInterface $environment, EventDispatcherInterface $eventDisptacher = null)
 {
     $this->setRouter($router)->setEnvironment($environment)->setEventDispatcher($eventDisptacher ?? EventDispatcher::getGlobal());
 }
예제 #5
0
class EventTest extends \PHPUnit_Framework_TestCase
{
    public function testDispatcher()
    {
        $event = new Event('PropagationTestEvent');
        $dispatcher = new EventDispatcher();
        $listener1 = new class
        {
            /* @var $this self */
            private $propagated = false;
            public function isPropagated()
            {
                return $this->propagated;
            }
            public function update(Event $e)
            {
                $this->propagated = true;
                $e->setActive(FALSE);
            }
        };
        $listener2 = new class
        {
            /* @var $this self */
            private $propagated = false;
            public function isPropagated()
            {
                return $this->propagated;
            }
            public function update(Event $e)
            {
                $this->propagated = true;
            }
        };
        $dispatcher->addListener($event, [$listener1, "update"]);
        $dispatcher->addListener($event, [$listener2, "update"]);
        $dispatcher->dispatch($event);
        $this->assertTrue($listener1->isPropagated());
        $this->assertFalse($listener2->isPropagated());
        $this->assertFalse($event->isActive());
        $dispatcher->removeListener($event, [$listener1, "update"]);
        $event->setActive(TRUE);
        $dispatcher->dispatch($event);
        $this->assertTrue($listener2->isPropagated());
    }
    public function testEvent()
    {
        $dataToTest = [new class
        {
            public function test()
            {
                return 'test';
            }
        }, ['abc', 1, 1.7, NULL], function ($abc) {
            return $abc . 'test';
        }];
        $event = new Event('TestEvent', $dataToTest[0]);
        $dispatcher = new EventDispatcher();
        $listener1 = new class($dataToTest[1])
        {
            private $data;
            public function __construct($data)
            {
                $this->data = $data;
            }
            public function update(Event $e)
            {
                $e->setData($this->data);
            }
        };
        $listener2 = new class($dataToTest[2])
        {
            private $data;
            public function __construct($data)
            {
                $this->data = $data;
            }
            public function update(Event $e)
            {
                $e->setData($this->data);
            }
        };
        $this->assertEquals('TestEvent', $event->getName());
        $this->assertEquals('test', $event->getData()->test());
        $dispatcher->addListener($event, [$listener1, "update"]);
        $dispatcher->dispatch($event);
        $this->assertEquals(['abc', 1, 1.7, NULL], $event->getData());
        $dispatcher->removeListener($event, [$listener1, "update"]);
        $dispatcher->addListener($event, [$listener2, "update"]);
        $dispatcher->dispatch($event);
        $this->assertEquals('testingtest', $event->getData()('testing'));
    }
}