??
EventManger? ?? ?? ??? ?? ??? ?? ?????.
??? ??/??? ?? ??
?? ?? ??? ??
??? ?? ???? ??
?? ????? ???? ???? ?? ?? ?? ????? ?? ???? ?? ???? ?? ? ???? ??? ??? ??? ? ????.
?? ??
????? ??? ?? EventManager? ?????.
use Zend\EventManager\EventManagerInterface; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; class Foo implements EventManagerAwareInterface { protected $events; public function setEventManager(EventManagerInterface $events) { $events->setIdentifiers(array( __CLASS__, get_called_class(), )); $this->events = $events; return $this; } public function getEventManager() { if (null === $this->events) { $this->setEventManager(new EventManager()); } return $this->events; } }
? ??? ???? ???? EventManager ????? ???? ? ???, ???? ?? ?? ? ????? ???? ? ????.
EventManager? ?? ???? ?????? ???? ??? ????. ?? ???? ????? ?? ??/??? ??? ??? ??, ????? ?? ?? ????? ???? ? ????? ?? ??/???? ???? ?? ???? ? ?? ?? ??? ?????. .
class Foo { // ... assume events definition from above public function bar($baz, $bat = null) { $params = compact('baz', 'bat'); $this->getEventManager()->trigger(__FUNCTION__, $this, $params); } }
????, ???? ????? ?? ???? ???? ???? ????? ??? ????. ?? ???? ??? ?? ??? ???? ???? EventManager? ?????. ??? ??? ??, ???? ? ????? ???? ?? ???? ?? Event ??? ?????. ???? ???? ???? ???????.
use Zend\Log\Factory as LogFactory; $log = LogFactory($someConfig); $foo = new Foo(); $foo->getEventManager()->attach('bar', function ($e) use ($log) { $event = $e->getName(); $target = get_class($e->getTarget()); $params = json_encode($e->getParams()); $log->info(sprintf( '%s called on %s, using params %s', $event, $target, $params )); }); // Results in log message: $foo->bar('baz', 'bat'); // reading: bar called on Foo, using params {"baz" : "baz", "bat" : "bat"}"
attach()? ? ?? ??? ??? ?????. ? ????? ??? ?? ?? ??? ???? ?? ??? ?????. ??? ??? ?? ??, ?? ??, ?? ???? ???? ???, ?? ?? ???? ???? ???? ??? ?? ??? ??? ?? ????. ?? ? ? ?? PHP ??? ?????.
??? EventManager ???? ?? ????? ???? ?? ???? ???? ?? ?? ????. Zend Framework? SharedEventCollection ??? ?? ?? ?????. ??? ??? ? ??? SharedEventCollection? ???? ??? EventManager ????? ??? ? ??? EventManager ????? ?? ???? ?????. SharedEventCollection? ??? ???? ?? ??? ???? ?? ?????. ??? ???? ?? EventManager? ??? ????? ?? ??? ?? ????(??? ????)? ?????. EventManager ????? ??? ? __CLASS__? ??? ????? ??????? SharedEventCollection? ???? ?? ?? ? ?? ???? ???? ??? ???? ???? ????? ??? ? ????. ?? ??, EventManager ????? ??? SharedEventManager ????? ??? ????(?: ??? ??? ??) ?? ?? ???? ?? ???? ?? ??? ? ????.
use Zend\Log\Factory as LogFactory; // Assume $events is a Zend\EventManager\SharedEventManager instance $log = LogFactory($someConfig); $events->attach('Foo', 'bar', function ($e) use ($log) { $event = $e->getName(); $target = get_class($e->getTarget()); $params = json_encode($e->getParams()); $log->info(sprintf( '%s called on %s, using params %s', $event, $target, $params )); }); // Later, instantiate Foo: $foo = new Foo(); $foo->getEventManager()->setSharedEventCollection($events); // And we can still trigger the above event: $foo->bar('baz', 'bat'); // results in log message: // bar called on Foo, using params {"baz" : "baz", "bat" : "bat"}"
??: StaticEventManager
2.0.0beta3??? StaticEventManager ???? SharedEventCollection?? ??? ? ????. ??? ?? ??? StaticEventManager::getInstance()? ???? ????? ??? ? ?? SharedEventCollection? ????? ??? ??? ?? ??? ??? ????.
??? ???????? ? ?? ???? ??? 2.0.0beta4??? SharedEventManager ????? ???? ?? ??? EventManager ????? ???? ??? ?????.
????? ???
??? ?? ????? ?? ?? ?? ???? ?? ??? ???? ????? ?? ??? ???, ?? ???? ? ?? ???? ??? ?? ????. . EventManager ?? ??? ?? ?????.
? ?? ?? ??? ??
$events = new EventManager(); $events->attach(array('these', 'are', 'event', 'names'), $callback);
?????? ?? ??
$events = new EventManager(); $events->attach('*', $callback);
????? ???? ?? ????? ? ??? ?????. ?? ??? ???? ?? ??????.
?? ??? ???? ???? ??? ? ?? ???? ?? ??? ????? ?????.
SharedEventManager? ?? ? ?? ?? ??? ??
$events = new SharedEventManager(); // Attach to many events on the context "foo" $events->attach('foo', array('these', 'are', 'event', 'names'), $callback); // Attach to many events on the contexts "foo" and "bar" $events->attach(array('foo', 'bar'), array('these', 'are', 'event', 'names'), $callback);
????? ???? ?? ????? ??? ?? ???? ?????.
SharedEventManager? ?? ?? ???? ? ?? ?????.
$events = new SharedEventManager(); // Attach to all events on the context "foo" $events->attach('foo', '*', $callback); // Attach to all events on the contexts "foo" and "bar" $events->attach(array('foo', 'bar'), '*', $callback);
????? ???? ?? ????? ??? ?? ???? ?????.
? ??? "foo" ? "bar" ????? ????, ???? ????? ??? ????? ??? ?????.
?? ??
EventManager ??
???
??? EventManager ????? SharedEventManager ??? ?? ???? ? ??? ?? ??? ??? ??? ? ????.
event_class
????? ??? ???? ???? ? ???? ?? Event ???? ?????.
shared_collections
???? ???? ?? SharedEventCollection ???????.
?? ??? ???
__construct
__construct(null|string|int Sidentifier)
??? ?? ??? ???? ???? ? EventManager ????? ?????. ???? ???? ??.
setEventClass
setEventClass(string $class)
???? ???? ???? ???? ??? ? ??? ?? Event ??? ??? ?????.
setSharedCollections
setSharedCollections(SharedEventCollection $collections=null)
???? ???? ? ???? SharedEventCollection ???????.
getSharedCollections
getSharedCollections()
?? ??? SharedEventCollection ????? ?????. ???? ???? ?? ?? ?? ??? SharedEventCollection ????? ?????.
trigger
trigger(string $event, Mixed $target, Mixed $argv, callback $callback)
??? ???? ?? ?? ???? ??????. $event? ?? ?? ??/??? ??? ???? ??? ?? ".pre", ".post" ?? ???? ?? ????. $context? ?? ??? ??????? ??? ???? ????? ?? ?? ??? ????? ???. $params? ????? ?? ?? ?? ArrayAccess ?????? ???. ??/???? ??? ????? ???? ?? ????(???? compact()? ??? ?? ????). ? ???? ??? ??? ?? ??? TriggerUntil()? ???? ?????.
???? ??? ???? ??? ?? ???? ?? ??? ?? ???? ? ??? ? ?? ResponseCollection? ????? ?????.
triggerUntil
triggerUntil(string $event, Mixed $context, Mixed $argv, callback $callback)
trigger( )? ????? ??? ???? ?? ?? ???? ??????. , ?? ? ???? ?? ?? $callback? ?????. $callback? ?? ? ?? ???? ???? ??? ?????. $result->stopped()? ???? ?? ???? ? ????.
attach
attach(string $event, callback $callback, int $priority)
EventManager ????? $callback? ???? $event ???? ?????. $priority? ???? ?? ?? ??? ???? ???? ?? ??? ??? ???? ? ?? ?? ?? ?????. (?? ????? "1"?? ?? ??? ?????.)
???? ZendStdlibCallbackHandler? ????? ????, ??? ?? ??? ? ?? detach()? ??? ? ????.
attachAggregate
attachAggregate(string|ListenerAggregate $aggregate)
???? $aggregate? ???? ?? ???? ????????. ?? ?? $aggregate? EventManager ????? attachment() ???? ???? ???? ??? ? ????.
ListenerAggregate ????? ?????.
detach
detach(CallbackHandler $listener)
?? ???? ???? $listener? ???? ?? ???? ???? ? ?? ????? ??? ???.
???? ???? ?? ??? ?? ? ??? ????, ??? ??? ?? ??? ?????.
detachAggregate
detachAggregate(ListenerAggregate $aggregate)
?? ???? ???? ?? ?? ??? ?? ???? ???? ???? ?????. ???? Remove???.
???? ???? ?? ??? ?? ? ??? ????, ??? ??? ?? ??? ?????.
getEvents
getEvent()
???? ??? ?? ??? ??? ??? ??? ?????.
getListeners
getListeners(string $event)
$event
clearListeners
clearListeners? ??? ?? ???? ?? ZendStdlibPriorityQueue ????? ?????. (??? $event)
$event? ??? ?? ???? ?????.
prepareArgs
prepareArgs(array $args)
??? $args?? ArrayObject? ?????. ?? ??? ???? ???? ???? ??? ?? ??? ? ? ??? ???? ?? ??? ??? ? ??? ??? ??? ?????.
Zend Framework 2.0 Event Manager(The EventManager) ?? ????? ??? ? ?? ??? ??? PHP ??? ????? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)