public function checkUserCredentials(Event $e) { if ($e->getParams()['username'] == 'test_event_true') { $e->stopPropagation(); return true; } if ($e->getParams()['username'] == 'test_event_false') { $e->stopPropagation(); return false; } }
/** * Determines if we're dealing with the required Resource * before dispatching to actions * * @param Event $e * @return mixed|void */ public function dispatch(Event $e) { switch ($e->getName()) { case 'create.post': case 'update.post': case 'patch.post': /** * Redirect client to newly created resource */ $controller = $e->getTarget(); if ($controller instanceof ResourceController) { $resource = $controller->getResource(); if ($resource instanceof Resource) { $model = $e->getParam('resource'); if ($model instanceof ResourceJsonModel) { $object = $model->getPayload(); if ($object instanceof BackendResourceInterface) { $e->stopPropagation(true); $response = $controller->redirect()->toRoute('api/default', array('resource' => $resource->getIdentifier(), 'id' => $object->getId())); return $response; //@TODO remove until fixed CORS redirect } } } } break; } }
public function tocar(Event $objEvent) { echo "<HR>"; echo "A buzina está tocando"; echo "<BR>"; echo "O alarme foi disparado por: "; echo $objEvent->getTarget()->getNome(); $objEvent->stopPropagation(true); return $this; }
/** * Perform an ACL check when a AuthorizedDirectObject is dispatched. * * @param \Zend\Mvc\MvcEvent $event * @return null|array */ public function onDispatchDirect(Event $event) { $object = $event->getParam('object'); $method = $event->getParam('rpc')->getMethod(); // Check ACL if ($object instanceof \JaztecAcl\Direct\AuthorizedDirectObject) { if (!$object->checkAcl($method)) { $event->stopPropagation(true); return $object->notAllowed(); } } }
public function postSend(Event $e) { $response = $e->getTarget(); $statusCode = $response->getStatusCode(); $cache = $this->getCache(); if ($statusCode == 304) { $response = $cache->getItem($this->cacheKey); } else { $cache->setItem($this->cacheKey, $response); $headers = $response->getHeaders(); $etag = $headers->get('Etag')->getFieldValue(); $tags = array('etag' => $etag); $cache->setTags($this->cacheKey, $tags); } $e->stopPropagation(true); return $response; }
public function testTriggerUntilSetsStopPropagationFlagToFalse() { $marker = (object) array('propagationIsStopped' => true); $this->events->attach('foo', function ($e) use($marker) { $marker->propagationIsStopped = $e->propagationIsStopped(); }); $criteria = function ($r) { return false; }; $event = new Event(); $event->stopPropagation(true); $this->events->triggerUntil('foo', $event, $criteria); $this->assertFalse($marker->propagationIsStopped); $this->assertFalse($event->propagationIsStopped()); }
/** * Save the image block and create a cropped image if necessary * @param \Zend\EventManager\Event $event * @return array|\DotsBlock\Db\Entity\Block|object|string */ public function saveBlock(Event $event) { $request = $event->getParam('request'); $locator = Registry::get('service_locator'); $appConfig = $locator->get('ApplicationConfig'); $modelImageBlock = $locator->get('DotsImageBlock\\Db\\Model\\ImageBlock'); $block = $event->getTarget(); $form = new MultiForm(array('image_content' => new ImageContentForm())); $data = array('image_content' => $request->getPost()); $files = $request->getFiles(); $data['image_content']['original_src'] = $files['original_src']['name']; $form->setData($data); if ($form->isValid()) { $data = $form->getInputFilter()->getValues(); if ($block->id) { $imageBlock = $modelImageBlock->getByBlockId($block->id); } else { $block->save(); $imageBlock = new ImageBlock(); $imageBlock->block_id = $block->id; } $imageBlock->alt = $data['image_content']['alt']; $imageBlock->display_width = $data['image_content']['display_width']; $imageBlock->display_height = $data['image_content']['display_height']; $editedCrop = $imageBlock->crop_x1 != $data['image_content']['crop_x1'] || $imageBlock->crop_y1 != $data['image_content']['crop_y1'] || $imageBlock->crop_x2 != $data['image_content']['crop_x2'] || $imageBlock->crop_y2 != $data['image_content']['crop_y2']; $imageBlock->crop_x1 = $data['image_content']['crop_x1']; $imageBlock->crop_y1 = $data['image_content']['crop_y1']; $imageBlock->crop_x2 = $data['image_content']['crop_x2']; $imageBlock->crop_y2 = $data['image_content']['crop_y2']; if (!empty($files['original_src']['tmp_name'])) { $upload = new Upload(array('path' => 'data/uploads/', 'destination' => $appConfig['public_path'] . '/')); $path = $upload->process($files); $data['image_content']['original_src'] = $path['original_src']; } if (!($imageBlock->id && empty($data['image_content']['original_src']))) { // success - do something with the uploaded file $fullFilePath = $data['image_content']['original_src']; if ($imageBlock->original_src) { unlink($appConfig['public_path'] . '/' . $imageBlock->original_src); } if ($imageBlock->src != $imageBlock->original_src) { unlink($appConfig['public_path'] . '/' . $imageBlock->src); } $imageBlock->original_src = $fullFilePath; $imageBlock->src = $fullFilePath; $thumb = PhpThumbFactory::create($appConfig['public_path'] . '/' . $imageBlock->original_src); $dimensions = $thumb->getCurrentDimensions(); $imageBlock->width = $dimensions['width']; $imageBlock->height = $dimensions['height']; } if ($editedCrop) { if ($imageBlock->src != $imageBlock->original_src) { unlink($appConfig['public_path'] . '/' . $imageBlock->src); } if ($imageBlock->crop_x1 !== "" && $imageBlock->crop_y1 !== "" && $imageBlock->crop_x2 !== "" && $imageBlock->crop_y2 !== "") { $thumb = PhpThumbFactory::create($appConfig['public_path'] . '/' . $imageBlock->original_src); if ($imageBlock->width && $imageBlock->height) { $w = $imageBlock->width; $h = $imageBlock->height; } else { $dimensions = $thumb->getCurrentDimensions(); $imageBlock->width = $w = $dimensions['width']; $imageBlock->height = $h = $dimensions['height']; } $x1 = round($imageBlock->crop_x1 * $w / 100); $y1 = round($imageBlock->crop_y1 * $h / 100); $x2 = round($imageBlock->crop_x2 * $w / 100); $y2 = round($imageBlock->crop_y2 * $h / 100); $thumb->crop($x1, $y1, $x2 - $x1, $y2 - $y1); $filename = basename($imageBlock->original_src); $filename = substr($filename, 0, strrpos($filename, '.')) . '.jpg'; $filename = 'data/uploads/edited/' . uniqid(rand()) . '_' . $filename; $thumb->save($appConfig['public_path'] . '/' . $filename, 'jpg'); $imageBlock->src = $filename; } else { $imageBlock->src = $imageBlock->original_src; } } $imageBlock->save(); return $block; } $event->stopPropagation(); $errors = $form->getMessages(); return $errors; }
/** * Validate and Filter content passed to the Resource * * By default this will prevent XSS and malicious * code being passed to the backend. * * Further event propagation is stopped to prevent * additional manipulation to reduce further risk. * * @param Event $event * @return array|null */ public function validateContent(Event $event) { $controller = $event->getTarget(); if ($controller instanceof ResourceController) { $request = $event->getTarget()->getRequest(); if (!$request instanceof HttpRequest) { return; } if (in_array($request->getMethod(), $this->methodsWithoutBodies)) { return; } $resource = $controller->getResource(); if ($resource instanceof Resource) { /** * Check Request method is allowed by Resource * Usually this would be picked up by Access Control, * however we should always check */ if (!in_array($request->getMethod(), $resource->getResourceHttpMethods())) { return; } $inputFilter = $resource->getInputFilter(); if (!$inputFilter instanceof InputFilter) { return; } try { $data = $event->getParam('data', array()); if ($request->isPatch()) { // Only filter values that have been provided $inputFilter->setValidationGroup(array_keys($data)); } $inputFilter->setData($data); if ($inputFilter->isValid()) { $filteredData = $inputFilter->getValues(); $event->stopPropagation(true); return array_merge($data, $filteredData); } return new ProblemResponse(new Problem(422, 'Failed Validation', null, null, ['validation_messages' => $inputFilter->getMessages()])); } catch (\Exception $ex) { return new ProblemResponse(new Problem(400, 'Invalid data specified in request')); } } } }
/** * Determine whether a navigation page is allowed. * * @param Event $event * @return bool */ public function navigationPageIsAllowed(Event $event) { $accepted = true; $params = $event->getParams(); $acl = $params['acl']; $page = $params['page']; if (!$acl) { return $accepted; } $resource = $page->getResource(); $privilege = $page->getPrivilege(); if ($resource || $privilege) { $accepted = $acl->hasResource($resource) && $acl->userIsAllowed($resource, $privilege); } $event->stopPropagation(); return $accepted; }
/** * Save html block * @param \Zend\EventManager\Event $event * @return array|\DotsBlock\Db\Entity\Block|object|string */ public function saveBlock(Event $event) { $locator = Registry::get('service_locator'); $modelHtmlBlock = $locator->get('DotsHtmlBlock\\Db\\Model\\HtmlBlock'); $block = $event->getTarget(); $request = $event->getParam('request'); $form = new MultiForm(array('html_content' => new HtmlContentForm())); $form->setData($request->getPost()->toArray()); if ($form->isValid()) { $data = $form->getInputFilter()->getValues(); if ($block->id) { $htmlBlock = $modelHtmlBlock->getByBlockId($block->id); } else { $block->save(); $htmlBlock = new HtmlBlock(); $htmlBlock->block_id = $block->id; } $htmlBlock->content = $data['html_content']['content']; $htmlBlock->save(); return $block; } $event->stopPropagation(); $errors = $form->getMessages(); return $errors; }