public function clearCache($id) { $event = new Event(); $event->setParam('id', $id); $result = $this->getEventManager()->trigger('clear', $event); return $result->last(); }
/** * Check other modules and register comments if available * * @param Event $e * @return void */ public function checkModules(Event $e) { $module = $e->getParam('module'); $modules = Pi::registry('module')->read(); if (isset($modules['comment'])) { unset($modules['comment']); } $moduleList = array_keys($modules); foreach ($moduleList as $mod) { $options = Pi::service('module')->loadMeta($mod, 'comment', true); if (empty($options)) { continue; } /* if (is_string($options)) { $optionsFile = sprintf( '%s/%s/config/%s', Pi::path('module'), Pi::service('module')->directory($mod), $options ); $options = include $optionsFile; if (empty($options) || !is_array($options)) { continue; } } */ $resourceHandler = new CommentResource($options); $e->setParam('module', $mod); $resourceHandler->setEvent($e); $resourceHandler->installAction(); } $e->setParam('module', $module); }
public function setBusinessSlug(Event $e) { $data = $e->getParam('data'); if (!$data['slug']) { $data['slug'] = $data['company']; } $e->setParam('data', $data); }
public function addVocabularyServices(Event $event) { $vocabs = $this->getServiceLocator()->get('Omeka\\ApiManager')->search('custom_vocabs')->getContent(); if (!$vocabs) { return; } $names = $event->getParam('registered_names'); foreach ($vocabs as $vocab) { $names[] = 'customvocab:' . $vocab->id(); } $event->setParam('registered_names', $names); }
/** * @param Event $e */ public function preSave(Event $e) { $articleService = $this->getService('UthandoArticle'); $model = $e->getParam('data'); $article = $model->getArticle(); $article->setDateModified(); $result = $articleService->save($article); if (!$model->getArticleId()) { $model->setArticleId($result); } $e->setParam('data', $model); }
/** * Check module model availability * * @param Event $e * @return bool */ public function checkModules(Event $e) { $module = $this->event->getParam('module'); $model = Pi::mdel('module'); //$rowset = $model->select(array('dirname <> ?' => $module)); $count = $model->count(array('dirname <> ?' => $module)); if ($count > 0) { $result = array('status' => false, 'message' => 'Modules are not unistalled completely.'); $e->setParam('result', $result); return false; } return true; }
/** * 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; } } }
/** * Check other modules and install profiles if available * * @param Event $e * @return void */ public function checkModules(Event $e) { $module = $e->getParam('module'); $modules = Pi::registry('module')->read(); if (isset($modules['user'])) { unset($modules['user']); } $moduleList = array_keys($modules); foreach ($moduleList as $mod) { $options = Pi::service('module')->loadMeta($mod, 'user', true); if (empty($options)) { continue; } $resourceHandler = new UserResource($options); $e->setParam('module', $mod); $resourceHandler->setEvent($e); $resourceHandler->installAction(); } $e->setParam('module', $module); }
/** * @param Event $e */ public function getSubscriptionList(Event $e) { /* @var $form \UthandoUser\Form\Register */ $form = $e->getParam('form'); $post = $e->getParam('post'); if (!$form instanceof Register) { return; } /* @var \UthandoNewsletter\Form\Element\SubscriptionList $subscriptionList */ $subscriptionList = $e->getTarget()->getServiceLocator()->get('FormElementManager')->get('UthandoNewsletterSubscriptionList'); if (0 === count($subscriptionList->getValueOptions())) { return; } $subscriptionList->setOptions(['label' => 'Newsletter', 'twb-layout' => TwbBundleForm::LAYOUT_HORIZONTAL, 'column-size' => 'sm-10', 'label_attributes' => ['class' => 'col-sm-2']]); if (isset($post['subscribe'])) { $subscriptionList->setValue($post['subscribe']); } $form->add($subscriptionList); $validationGroup = $form->getValidationGroup(); $validationGroup[] = 'subscribe'; $form->setValidationGroup($validationGroup); $e->setParam('form', $form); }
/** * Install default theme * * @param Event $e * @return bool */ public function installTheme(Event $e) { $themeInstaller = new ThemeInstaller(); $result = $themeInstaller->install('default'); if (is_array($result)) { $status = $result['status']; if (!$status) { $ret = $e->getParam('result'); $ret['theme'] = $result; $e->setParam('result', $ret); } } else { $status = (bool) $result; } return $status; }
/** * Set an individual event parameter * * @param string $name * @param mixed $value * @return $this */ public function setParam($name, $value) { switch ($name) { case 'processor': $this->setProcessor($value); break; case 'message': $this->setMessage($value); break; case 'result': $this->setResult($value); break; default: parent::setParam($name, $value); break; } return $this; }
/** * Load theme meta * @param Event $e * @return void */ public function loadConfig(Event $e) { $config = Pi::service('theme')->loadConfig($e->getParam('name')); $e->setParam('config', $config); }
/** * Load module meta * * @param Event $e * @return void */ public function loadConfig(Event $e) { $directory = $e->getParam('directory'); $config = Pi::service('module')->loadMeta($directory, null, true); $e->setParam('config', $config); if (!$e->getParam('title')) { $e->setParam('title', $config['meta']['title']); } }
/** * Password pre saving checks * * @param Event $e * @throws UthandoUserException */ public function preSave(Event $e) { $data = $e->getParam('data'); if ($data instanceof UserModel) { $data = $this->getMapper()->extract($data); } if (array_key_exists('passwd', $data) && '' != $data['passwd']) { $data['passwd'] = $this->createPassword($data['passwd']); } else { unset($data['passwd']); } $e->setParam('data', $data); }
/** * 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); } $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 (self::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; } }
/** * Initize module data * * @param Event $e * @return boolean */ public function initModuleData(Event $e) { $result = true; // Skip if the initial data is not exists $sqlPath = sprintf('%s/%s', Pi::path('module'), self::INIT_FILE_NAME); if (!file_exists($sqlPath)) { return $e->setParam('result', $result); } // Get module name and prefix of table $module = $this->event->getParam('module'); $prefix = Pi::db()->getTablePrefix(); // Fetch data and insert into database $file = fopen($sqlPath, 'r'); if ($file) { $sql = fread($file, filesize($sqlPath)); $sql = preg_replace('|{prefix}|', $prefix, $sql); $sql = preg_replace('|{module}|', $module, $sql); $sql = preg_replace('|{upload-url}|', Pi::url('upload/' . $module), $sql); $sql = preg_replace('|upload\\/article|', 'upload\\/' . $module, $sql); try { $isInsert = Pi::db()->getAdapter()->query($sql, 'execute'); } catch (\Exception $exception) { return false; } // Copy uploaded data $staticFilename = sprintf('%s/%s', Pi::path('module'), self::INIT_STATIC_NAME); if (file_exists($staticFilename)) { $targetFilename = sprintf('%s/%s/%s', Pi::path('upload'), $module, basename($staticFilename)); // Create folder $targetPath = dirname($targetFilename); if (!is_dir($targetPath)) { if (Pi::service('file')->mkdir($targetPath)) { chmod($targetPath, 0777); } } // Copy data and decompression $isCorrect = copy($staticFilename, $targetFilename); if ($isCorrect) { $zip = new ZipArchive(); if ($zip->open($targetFilename) === TRUE) { $zip->extractTo(dirname($targetFilename)); $zip->close(); @unlink($targetFilename); } } } } else { $result = false; } return $result; }
/** * {@inheritdoc} */ public function setParam($name, $value) { if (in_array($name, $this->specializedParams)) { $this->{'set' . $name}($value); } else { parent::setParam($name, $value); } return $this; }
public function testGetSetEvent() { $defaultEvent = $this->queue->getEvent(); $this->assertInstanceOf(QueueEvent::class, $defaultEvent); $newEvent = new Event(); $newEvent->setParam('foo', 'bar'); $this->assertInstanceOf(Queue::class, $this->queue->setEvent($newEvent)); //Test recast $this->assertInstanceOf(QueueEvent::class, $this->queue->getEvent()); $this->assertSame('bar', $this->queue->getEvent()->getParam('foo')); //Restore original event $this->queue->setEvent($defaultEvent); }
/** * Test * * @return void */ public function testRenderWithHelperVariable() { $template = array(); $template['template'] = '<?= $this->event->getParam(\'user\')->getName() ?> has saved the user model ' . '<a href="<?= $this->url(\'config/user/edit\', array(\'id\' => $this->event->getParam' . '(\'object\')->getId())) ?>"><?= $this->event->getParam(\'object\')->getId() ?></a>'; $template['event_identifier'] = 'Gc\\User\\Model'; $template['event_name'] = 'on.something'; $result = 'Pierre Rambaud has saved the user model ' . '<a href="/admin/config/user/edit/1">1</a>'; $event = new Event(); $user = new UserModel(); $user->setFirstname('Pierre'); $user->setLastname('Rambaud'); $event->setParam('user', $user); $user = new UserModel(); $user->setData('id', 1); $event->setParam('object', $user); $this->assertEquals($result, $this->object->render($event, $template)); }
/** * Filter the JSON-LD for YouTube media. * * @param Event $event */ public function filterYoutubeMediaJsonLd(Event $event) { if ('youtube' !== $event->getTarget()->ingester()) { return; } $data = $event->getTarget()->mediaData(); $jsonLd = $event->getParam('jsonLd'); $jsonLd['@context']['time'] = 'http://www.w3.org/2006/time#'; $jsonLd['time:hasBeginning'] = ['@value' => $data['start'], '@type' => 'time:seconds']; $jsonLd['time:hasEnd'] = ['@value' => $data['end'], '@type' => 'time:seconds']; $event->setParam('jsonLd', $jsonLd); }
/** * @group 166 */ public function testOnFetchWillRetainResourceClassIfEventFetchFlagIsFalse() { $originalData = array( 'controller_service_name' => 'BarConf\Rest\Barbaz\Controller', 'resource_class' => 'BarConf\Rest\Barbaz\BarbazResource', 'route_name' => 'bar-conf.rest.barbaz', 'route_match' => '/api/barbaz', 'entity_class' => 'BarConf\Rest\Barbaz\BarbazEntity', ); $entity = new RestServiceEntity(); $entity->exchangeArray($originalData); $config = array( 'zf-apigility' => array('db-connected' => array( 'BarConf\Rest\Barbaz\BarbazResource' => array( 'adapter_name' => 'Db\Barbaz', 'table_name' => 'barbaz', 'hydrator_name' => 'ObjectProperty', ), ))); $event = new Event(); $event->setParam('entity', $entity); $event->setParam('config', $config); $event->setParam('fetch', false); $result = $this->model->onFetch($event); $this->assertInstanceOf('ZF\Apigility\Admin\Model\DbConnectedRestServiceEntity', $result); $this->assertEquals('BarConf\Rest\Barbaz\BarbazResource', $result->resourceClass); $asArray = $result->getArrayCopy(); $this->assertArrayHasKey('resource_class', $asArray); $this->assertEquals('BarConf\Rest\Barbaz\BarbazResource', $asArray['resource_class']); }
protected function getMetadataEvent() { $event = new Event(); $metadata = $this->getEntityManager()->getClassMetadata('DoctrineORMModuleTest\\Assets\\Entity\\FormEntity'); $event->setParam('metadata', $metadata); return $event; }
/** * 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; } }
public function testInjectEsi() { $block = new ViewModel(); $block->setOption('esi', ['ttl' => 120]); $block->setTemplate('default'); $event = new Event(); $event->setParam('block', $block); $this->listener->determineEsiProcessing($this->mvcEvent); $this->listener->injectEsi($event); $this->assertEquals('default', $block->getTemplate()); $this->listener->setCanUseEsi(true); $this->listener->injectEsi($event); $this->assertEquals(InjectCacheHeaderListener::ESI_TEMPLATE, $block->getTemplate()); }
/** * Set an individual event parameter * * @param string $name * @param mixed $value * @return ViewEvent */ public function setParam($name, $value) { switch ($name) { case 'model': $this->setModel($value); break; case 'renderer': $this->setRenderer($value); break; case 'request': $this->setRequest($value); break; case 'response': $this->setResponse($value); break; case 'result': $this->setResult($value); break; default: parent::setParam($name, $value); break; } return $this; }
/** * @param Event $e * @throws \UthandoCommon\Service\ServiceException */ public function updateSubscriptions(Event $e) { /* @var $form SubscriberForm */ $form = $e->getParam('form'); /* @var $model SubscriberModel */ $model = $form->getData(); $subscriberId = $model->getSubscriberId() ?: $e->getParam('saved'); /* @var $newsletterService \UthandoNewsletter\Service\Newsletter */ $newsletterService = $this->getService('UthandoNewsletter'); /* @var $subscriptionService \UthandoNewsletter\Service\Subscription */ $subscriptionService = $this->getService('UthandoNewsletterSubscription'); $newsletters = $newsletterService->fetchAll(); $subscriber = $this->getSubscriberWithSubscriptions($subscriberId); $subscribe = $model->getSubscribe(); $result = false; // if we have a subscriber id then update subscriptions // where values are positive if ($subscriberId) { /* @var $newsletter \UthandoNewsletter\Model\Newsletter */ foreach ($newsletters as $newsletter) { $subscribeToNewsletter = in_array($newsletter->getNewsletterId(), $subscribe); $subscription = $subscriber->getSubscriptions($newsletter->getNewsletterId()); // if we want to subscribe and no record exists if (!$subscription && $subscribeToNewsletter) { $result = $subscriptionService->save(['subscriptionId' => null, 'newsletterId' => $newsletter->getNewsletterId(), 'subscriberId' => $subscriber->getSubscriberId()]); } // if we want to un-subscribe if ($subscription && !$subscribeToNewsletter) { $result = $subscriptionService->delete($subscription->getSubscriptionId()); } } } $e->setParam('result', $result); }