本文整理汇总了PHP中Zend\EventManager\Event::setParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::setParams方法的具体用法?PHP Event::setParams怎么用?PHP Event::setParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\Event
的用法示例。
在下文中一共展示了Event::setParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setParams
/**
* Set parameters
*
* Overwrites parameters
*
* @param array|ArrayAccess|Traversable|object $params
* @return ModulesEvent
*/
public function setParams($params)
{
if ($params instanceof Traversable) {
$params = iterator_to_array($params);
} else {
if (is_object($params) && !$params instanceof ArrayAccess) {
$params = (array) $params;
}
}
return parent::setParams($params);
}
示例2: createAnnotation
/**
* Create Annotation
*
* @param array $annotationData
* @return false|\stdClass
*/
public function createAnnotation(array $annotationData)
{
$event = new Event();
$event->setName(self::EVENT_CREATE_ANNOTATION);
$event->setTarget($this);
$event->setParams(array('class' => $annotationData[0], 'content' => $annotationData[1], 'raw' => $annotationData[2]));
$results = $this->getEventManager()->trigger($event, function ($r) {
return is_object($r);
});
$annotation = $results->last();
return is_object($annotation) ? $annotation : false;
}
示例3: configureElement
/**
* Configure an element from annotations
*
* @param AnnotationCollection $annotations
* @param PropertyReflection $reflection
* @param ArrayObject $formSpec
* @param ArrayObject $filterSpec
* @return void
*
* @triggers checkForExclude
* @triggers discoverName
* @triggers configureElement
*/
protected function configureElement($annotations, $reflection, $formSpec, $filterSpec)
{
// If the element is marked as exclude, return early
if ($this->checkForExclude($annotations)) {
return;
}
$events = $this->getEventManager();
$name = $this->discoverName($annotations, $reflection);
$elementSpec = new ArrayObject(['flags' => [], 'spec' => ['name' => $name]]);
$inputSpec = new ArrayObject(['name' => $name]);
$event = new Event();
$event->setParams(['name' => $name, 'elementSpec' => $elementSpec, 'inputSpec' => $inputSpec, 'formSpec' => $formSpec, 'filterSpec' => $filterSpec]);
foreach ($annotations as $annotation) {
$event->setParam('annotation', $annotation);
$events->trigger(__FUNCTION__, $this, $event);
}
// Since "filters", "type", "validators" is a reserved names in the filter specification,
// we need to add the specification without the name as the key.
// In all other cases, though, the name is fine.
if ($event->getParam('inputSpec')->count() > 1 || $annotations->hasAnnotation(Input::class)) {
if ($name === 'type' || $name === 'filters' || $name === 'validators') {
$filterSpec[] = $event->getParam('inputSpec');
} else {
$filterSpec[$name] = $event->getParam('inputSpec');
}
}
$elementSpec = $event->getParam('elementSpec');
$type = isset($elementSpec['spec']['type']) ? $elementSpec['spec']['type'] : Element::class;
// Compose as a fieldset or an element, based on specification type.
// If preserve defined order is true, all elements are composed as elements to keep their ordering
if (!$this->preserveDefinedOrder() && is_subclass_of($type, FieldsetInterface::class)) {
if (!isset($formSpec['fieldsets'])) {
$formSpec['fieldsets'] = [];
}
if (isset($formSpec['fieldsets'][$name])) {
$formSpec['fieldsets'][] = $elementSpec;
} else {
$formSpec['fieldsets'][$name] = $elementSpec;
}
} else {
if (!isset($formSpec['elements'])) {
$formSpec['elements'] = [];
}
if (isset($formSpec['elements'][$name])) {
$formSpec['elements'][] = $elementSpec;
} else {
$formSpec['elements'][$name] = $elementSpec;
}
}
}
示例4: setParams
/**
* Overload setParams to inject request object, if passed via params
*
* @param array|ArrayAccess|object $params
* @return self
*/
public function setParams($params)
{
if (!is_array($params) && !is_object($params)) {
throw new InvalidArgumentException(sprintf('Event parameters must be an array or object; received "%s"', gettype($params)));
}
if (is_array($params) || $params instanceof ArrayAccess) {
if (isset($params['request'])) {
$this->setRequest($params['request']);
unset($params['request']);
}
}
parent::setParams($params);
return $this;
}
示例5: template
public function template($template)
{
$controller = get_class($this->controller);
$services = $this->getController()->getServiceLocator();
$event = new Event();
$eventManager = $services->get('EventManager');
$eventManager->setIdentifiers('Mail');
$p = new Parameters(array('mail' => $this, 'template' => $template));
$event->setParams($p);
$eventManager->trigger('template.pre', $event);
// get all loaded modules
$moduleManager = $services->get('ModuleManager');
$loadedModules = $moduleManager->getModules();
//get_called_class
$controllerIdentifier = strtolower(substr($controller, 0, strpos($controller, '\\')));
$viewResolver = $this->getController()->getServiceLocator()->get('ViewResolver');
$templateHalf = 'mail/' . $template;
$resource = $viewResolver->resolve($templateHalf);
if (empty($resource)) {
$templateFull = $controllerIdentifier . '/mail/' . $template;
$resource = $viewResolver->resolve($templateFull);
}
$__vars = $this->param;
if (array_key_exists('this', $__vars)) {
unset($__vars['this']);
}
extract($__vars);
unset($__vars);
// remove $__vars from local scope
if ($resource) {
try {
ob_start();
include $resource;
$content = ob_get_clean();
$this->setBody($content);
} catch (\Exception $ex) {
ob_end_clean();
throw $ex;
}
$__vars = get_defined_vars();
foreach ($this->param as $key => $value) {
if (isset($__vars[$key])) {
unset($__vars[$key]);
}
}
unset($__vars['content'], $__vars['controllerIdentifier'], $__vars['controller'], $__vars['resource'], $__vars['template'], $__vars['viewResolver']);
$this->config = $__vars;
}
}
示例6: triggerEvent
/**
* Triggers the specified event on the defined context and return a concateneted string with the results
* @param string $eventName
* @param mixed $target
* @param array $argv
* @return string
*/
public function triggerEvent($eventName, $target, $argv)
{
//init the event with the target, params and name
$event = new Event();
$event->setTarget($target);
$event->setParams($argv);
$event->setName($eventName);
$content = "";
//trigger the event listeners
$responses = $this->events()->trigger($eventName, $event);
//merge all results and return the response
foreach ($responses as $response) {
$content .= $response;
}
return $content;
}
示例7: __call
/**
* Magic methods for install, uninstall, update, etc.
*
* @param string $method
* @param array $args
* @return bool
* @throws \InvalidArgumentException
*/
public function __call($method, $args)
{
if (!in_array($method, array('install', 'uninstall', 'update'))) {
throw new \InvalidArgumentException(sprintf('Invalid action "%s".', $method));
}
$name = array_shift($args);
$options = empty($args) ? array() : array_shift($args);
$version = isset($options['version']) ? $options['version'] : null;
$event = new Event();
$event->setParams(array('name' => $name, 'version' => $version, 'action' => $method, 'config' => array()));
$this->event = $event;
$this->attachDefaultListeners();
$this->getEventManager()->trigger('start', null, $event);
// Define callback used to determine whether or not to short-circuit
$shortCircuit = function ($r) {
if (false === $r) {
return true;
}
return false;
};
$result = $this->getEventManager()->trigger(sprintf('%s.pre', $method), null, $event, $shortCircuit);
if ($result->stopped()) {
return false;
}
$actionMethod = $method . 'Action';
$result = $this->{$actionMethod}();
if (!$result['status']) {
$ret = array($method => $result);
$this->event->setParam('result', $ret);
return false;
}
$result = $this->getEventManager()->trigger('process', null, $event, $shortCircuit);
if ($result->stopped()) {
return false;
}
$this->getEventManager()->trigger(sprintf('%s.post', $method), null, $event);
$this->getEventManager()->trigger('finish', null, $event);
$status = true;
$result = $event->getParam('result');
//foreach ($result as $action => $state) {
if ($result['status'] === false) {
$status = false;
//break;
}
//}
return $status;
}
示例8: __invoke
/**
* Triggers the specified event on the defined context and return a concateneted string with the results
*
* @param string $eventName
* @param mixed $target
* @param array $argv
* @return string
*/
public function __invoke($eventName, $target, $argv)
{
$alias = 'zfc-twig';
if (strpos($eventName, ':') !== false) {
$aux = explode(':', $eventName);
$alias = $aux[0];
$eventName = $aux[1];
}
//init the event with the target, params and name
$event = new Event();
$event->setTarget($target);
$event->setParams($argv);
$event->setName($eventName);
$content = "";
//trigger the event listeners
$responses = $this->events($alias)->trigger($eventName, $event);
//merge all results and return the response
foreach ($responses as $response) {
$content .= $response;
}
return $content;
}
示例9: setParams
public function setParams($params)
{
if (is_array($params)) {
if (isset($params['paginatorParams'])) {
$this->setPaginatorParams($params['paginatorParams']);
unset($params['paginatorParams']);
}
if (isset($params['paginators'])) {
$this->setPaginators($params['paginators']);
unset($params['paginators']);
}
if (isset($params['paginatorName'])) {
$this->setPaginatorName($params['paginatorName']);
unset($params['paginatorName']);
}
}
return parent::setParams($params);
}
示例10: configureElement
/**
* Configure an element from annotations
*
* @param AnnotationCollection $annotations
* @param \Zend\Code\Reflection\PropertyReflection $reflection
* @param ArrayObject $formSpec
* @param ArrayObject $filterSpec
* @return void
* @triggers checkForExclude
* @triggers discoverName
* @triggers configureElement
*/
protected function configureElement($annotations, $reflection, $formSpec, $filterSpec)
{
// If the element is marked as exclude, return early
if ($this->checkForExclude($annotations)) {
return;
}
$events = $this->getEventManager();
$name = $this->discoverName($annotations, $reflection);
$elementSpec = new ArrayObject(array('flags' => array(), 'spec' => array('name' => $name)));
$inputSpec = new ArrayObject(array('name' => $name));
$event = new Event();
$event->setParams(array('name' => $name, 'elementSpec' => $elementSpec, 'inputSpec' => $inputSpec, 'formSpec' => $formSpec, 'filterSpec' => $filterSpec));
foreach ($annotations as $annotation) {
$event->setParam('annotation', $annotation);
$events->trigger(__FUNCTION__, $this, $event);
}
// Since "type" is a reserved name in the filter specification,
// we need to add the specification without the name as the key.
// In all other cases, though, the name is fine.
if ($event->getParam('inputSpec')->count() > 1) {
if ($name === 'type') {
$filterSpec[] = $event->getParam('inputSpec');
} else {
$filterSpec[$name] = $event->getParam('inputSpec');
}
}
$elementSpec = $event->getParam('elementSpec');
$type = isset($elementSpec['spec']['type']) ? $elementSpec['spec']['type'] : 'Zend\\Form\\Element';
// Compose as a fieldset or an element, based on specification type
if (static::isSubclassOf($type, 'Zend\\Form\\FieldsetInterface')) {
if (!isset($formSpec['fieldsets'])) {
$formSpec['fieldsets'] = array();
}
$formSpec['fieldsets'][] = $elementSpec;
} else {
if (!isset($formSpec['elements'])) {
$formSpec['elements'] = array();
}
$formSpec['elements'][] = $elementSpec;
}
}
示例11: setParams
/**
* Set event parameters
*
* @param array|object|ArrayAccess $params
* @return ViewEvent
*/
public function setParams($params)
{
parent::setParams($params);
if (!is_array($params) && !$params instanceof ArrayAccess) {
return $this;
}
foreach (['model', 'renderer', 'request', 'response', 'result'] as $param) {
if (isset($params[$param])) {
$method = 'set' . $param;
$this->{$method}($params[$param]);
}
}
return $this;
}
示例12: testUpdateSubscriptionsReturnsAffectedRowWhenSubscribing
public function testUpdateSubscriptionsReturnsAffectedRowWhenSubscribing()
{
$event = new Event();
$subscriberModel = new SubscriberModel();
$subscriberModel->setSubscriberId(1)->setEmail('joe@bloggs.com')->setName('Joe Bloggs')->setSubscribe([1]);
$form = $this->getMock('UthandoNewsletter\\Form\\Subscriber');
$form->expects($this->once())->method('getData')->willReturn($subscriberModel);
$event->setParams(['form' => $form, 'saved' => 1]);
$subscriptionServiceMock = $this->getMock('UthandoNewsletter\\Service\\Subscription');
$subscriptionServiceMock->expects($this->any())->method('getSubscriptionsBySubscriberId')->willReturn([]);
$subscriptionServiceMock->expects($this->any())->method('save')->willReturn(1);
$this->serviceManager->get('UthandoServiceManager')->setService('UthandoNewsletterSubscription', $subscriptionServiceMock);
$service = $this->getService();
$service->updateSubscriptions($event);
$this->assertEquals(1, $event->getParam('result'));
}
示例13: setParams
/**
* Sets parameters.
*
* @internal Sets the job entity when passed in $params under the key/property named "job".
* This is because in the JobEventManager, the default event class is set to this,
*
* @since 0.19
*/
public function setParams($params)
{
if (is_array($params) && isset($params['job'])) {
$this->setJobEntity($params['job']);
unset($params['job']);
} elseif (is_object($params) && isset($params->job)) {
$this->setJobEntity($params->job);
}
return parent::setParams($params);
}
示例14: setParams
/**
* Sets parameters.
*
* @internal Sets the application entity when passed in $params under the key/property named "application".
* This is because in the ApplicationEventManager, the default event class is set to this,
*
* @since 0.25
*/
public function setParams($params)
{
if (is_array($params) && isset($params['application'])) {
$this->setApplicationEntity($params['application']);
unset($params['application']);
} elseif (is_object($params) && isset($params->application)) {
$this->setApplicationEntity($params->application);
}
if (is_array($params) && isset($params['user'])) {
$this->setUser($params['user']);
unset($params['user']);
}
if (is_array($params) && isset($params['status'])) {
$this->setStatus($params['status']);
unset($params['status']);
}
return parent::setParams($params);
}
示例15: parsePage
/**
* Parse a single page into a navigation configuration
*
* @param Page $page
* @return array
* @throws Exception\RuntimeException
*/
public function parsePage(PageInterface $page)
{
$meta = $page->getMetaData();
$navPage = Page::factory(array('type' => 'mvc', 'route' => (string) $page->getId(), 'label' => $meta->getNavigationTitle(), 'visible' => $page->isVisible()));
$event = new Event();
$event->setName(__FUNCTION__ . '.' . $page->getModule());
$event->setTarget($this);
$event->setParams(array('page' => $page, 'navigation' => $navPage));
$this->events->trigger($event);
return $navPage;
}