Fires an 'onBeforeImport' event.

@param Event $event
$event->params['element'] - model to be imported, manipulate this to change the model before it is saved
$event->params['value'] - data used to create the element model

@return null
432372
public function onBeforeExportFieldValue($element, $data)
    {
       $event = new ExportEvent(array(
          'element' => $element,
          'value' => $data
       ));
       $this->trigger($this::EVENT_BEFORE_EXPORT_FIELD_VALUE, $event);
       return $event->value;
    }
167662
public function onPackageAfterExecute(Event $event)
    {
        /**
         * @var AbstractPackage    $package
         * @var AbstractController $controller
         */
        $package    = $event['package'];
        $controller = $event['controller'];

        /**
         * @var Container $container
         * @var Collector $collector
         * @var Profiler  $profiler
         */
        $container = $package->getContainer();
        $collector = $container->get('debugger.collector');
        $profiler  = $container->get('profiler');

        $collector['controller.main'] = get_class($controller);

        $collector->push('controller.executed', [
            'controller' => get_class($controller),
            'task' => $event['task'],
            'input' => $controller->getInput()->toArray(),
            'variables' => $event['variables'],
        ]);

        $name = $package->getName();

        $profiler->mark(__FUNCTION__ . ' / ' . $name . ' (' . uniqid() . ')', [
            'tag' => 'package.process',
        ]);
    }
5278
public function onBeforeRouting(Event $event): void
    {
        /** @var WebApplication $app */
        $app = $event['app'];

        if ($app->get('system.offline', false) && !$app->get('system.debug')) {
            $app->server->setHandler(
                function (RequestInterface $request, ResponseInterface $response, callable $next = null) {
                    $view = new HtmlView();
                    $view->setLayout('windwalker.offline.offline');

                    return new HtmlResponse($view->render());
                }
            );

            $app->server->listen();

            die;
        }
    }
576518
public function onBeforeValidate($event)
    {
        foreach ($this->attributeValues as $name => $value) {

            $options = ArrayHelper::merge([
                'class' => DateValidator::className(),
                'format' => $value->localFormat[1],
            ], $this->validatorOptions);

            $validator = Yii::createObject($options);
            $validator->validateAttributes($this->owner, [$value->localAttribute]);
        }
    }
1168951
public function onBeforeExport($element , array $newElement)
    {
        $event = new ExportEvent(array(
            'element' => $element,
            'value' => $newElement
        ));
        $this->trigger($this::EVENT_BEFORE_EXPORT_ELEMENT, $event);
        return $event->value;
    }
780049
public static function onPreUpdate(Event $event)
    {
        $page = $event->getTarget();
        $eventArgs = $event->getEventArgs();
        $updateParents = false;
        $new = $old = null;

        $pageCountModifier = -1;
        if ($eventArgs instanceof PreUpdateEventArgs) {
            if ($page instanceof Page && $eventArgs->hasChangedField('_section')) {
                $old = $eventArgs->getOldValue('_section');
                $new = $eventArgs->getNewValue('_section');

                if ($new->getUid() === $page->getUid()) {
                    return;
                }
                $updateParents = true;
            }

            if ($page instanceof Page && $eventArgs->hasChangedField('_state')) {
                if ($page->getParent() !== null) {
                    if ($eventArgs->getNewValue('_state') >= 4) {
                        $old = $page->getParent()->getSection();
                        if (!$page->isLeaf()) {
                            $pageCountModifier = 0;
                        }
                    } else {
                        $new = $page->getParent()->getSection();
                    }
                    $updateParents = true;
                }
            }

            if ($page instanceof Section && $eventArgs->hasChangedField('_parent')) {
                $old = $eventArgs->getOldValue('_parent');
                $new = $eventArgs->getNewValue('_parent');
                $updateParents = true;
            }

            if ($updateParents) {
                $em = $event->getApplication()->getEntityManager();

                self::setSectionHasChildren($em, $old, $pageCountModifier);
                self::setSectionHasChildren($em, $new, +1);
            }
        }
    }
438884
public function beforePrepare(Event $event)
	{
		$command = $event['command'];
		$operation = $command->getOperation();
		$client = $command->getClient();

		if ($command->getName() !== 'updateEntity') return;
		if ($operation->getParam('collection')->getDefault() !== 'user') return;

		// Attempt to get the model's deleted at value from the array of values passed
		// to the command.
		$statusValue = false;

		if ($command->offsetExists(Model::DELETED_AT))
		{
			$statusValue = $command->offsetGet(Model::DELETED_AT);
		}
		elseif ($command->offsetExists('_kmd'))
		{
			$_kmd = array_dot($command->offsetGet('_kmd'));

			$statusField = MODEL::DELETED_AT;
			$statusField = str_replace('_kmd.', '', MODEL::DELETED_AT);

			if (array_key_exists($statusField, $_kmd))
			{
				$statusValue = $_kmd[$statusField];
			}
		}

		// Could not determine the status field.
		if ($statusValue === false)
		{
			return;
		}
		// Suspend the user.
		elseif (!is_null($statusValue))
		{
			$event->stopPropagation();

			$suspendCommand = $client->getCommand('deleteEntity', array(
				'collection' => 'user',
				'_id' => $command->offsetGet('_id'),
			));
			$suspendCommand->execute();
		}
		// Restore.
		else
		{
			$event->stopPropagation();

			$restoreCommand = $client->getCommand('restore', array(
				'_id' => $command->offsetGet('_id'),
			));
			$restoreCommand->execute();
		}
	}
918334
public function beforeRender(Event $event) {
		if (in_array('Captcha.Captcha', $this->controller->helpers) || isset($this->controller->helpers['Captcha.Captcha'])) {
			return;
		}

		$this->controller->helpers[] = 'Captcha.Captcha';
	}
1114797
public static function onApplicationInit(Event $event)
    {
        $application = $event->getTarget();
        $container = $application->getContainer();
        if ($container->hasParameter('bbapp.classcontent.exception_on_unknown_classname')) {
            $parameter = $container->getParameter('bbapp.classcontent.exception_on_unknown_classname');
        } else {
            $parameter = true;
        }

        if ('debug' === strtolower($parameter)) {
            AbstractClassContent::throwExceptionOnUnknownClassname($application->isDebugMode());
        } else {
            AbstractClassContent::throwExceptionOnUnknownClassname($parameter);
        }
    }
1097666
public function beforeRender(Event $event) {
		/** @var \Cake\Controller\Controller $controller */
		$controller = $event->getSubject();

		if (!$controller->getRequest()->is('ajax')) {
			return null;
		}

		$headerKey = $this->getConfig('headerKey');
		if (!$headerKey) {
			return null;
		}

		$ajaxMessages = array_merge_recursive(
			(array)$controller->getRequest()->getSession()->consume('Flash'),
			(array)Configure::consume('TransientFlash')
		);

		$array = [];
		foreach ($ajaxMessages as $key => $stack) {
			foreach ($stack as $message) {
				$array[$key][] = [
					'message' => $message['message'],
					'type' => $message['type'],
					'params' => $message['params']
				];
			}
		}

		// The header can be read with JavaScript and the flash messages can be displayed
		$this->getController()->setResponse($controller->getResponse()->withHeader($headerKey, json_encode($array)));
	}
357749
public function beforePrepare(Event $event)
	{
		$command = $event['command'];

		if ($command->getName() !== 'createEntity') return;
		if (!$command['_id']) return;

		$operation = $command->getOperation();
		$operation->setHttpMethod('PUT');
	}
736352
public function onRequestBeforeSend(Event $event)
    {
        if ($this->wireBodies) {
            $request = $event['request'];
            // Ensure that curl IO events are emitted
            $request->getCurlOptions()->set('emit_io', true);
            // We need to make special handling for content wiring and non-repeatable streams.
            if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()
                && (!$request->getBody()->isSeekable() || !$request->getBody()->isReadable())
            ) {
                // The body of the request cannot be recalled so logging the body will require us to buffer it
                $request->getParams()->set('request_wire', EntityBody::factory());
            }
            if (!$request->getResponseBody()->isRepeatable()) {
                // The body of the response cannot be recalled so logging the body will require us to buffer it
                $request->getParams()->set('response_wire', EntityBody::factory());
            }
        }
    }
451026
public function onBeforeSend(Event $event)
    {
        global $logger;
        $req        = $event['request'];
        $options    = $this->_options;
        $algorithms = array(
            'sha1',
            'sha256',
            'sha512'
        );

        if(empty($options['key']))
            $options['key'] = $this->_app->getConfiguration()->getSharedKey();
        if(empty($options['secret']))
            $options['secret'] = $this->_app->getConfiguration()->getSecretKey();

        if (!isset($options['key']) || !is_string($options['key']))
            throw new \Exception("options.key must be a String");
        if (isset($options['algorithm']) && !is_string($options['algorithm']))
            throw new \Exception("options.algorithm must be a String");
        if (isset($options['headers']) && !is_array($options['headers']))
            throw new \Exception("options.headers must be an array of Strings");

        $reqDate = $this->_rfc1123();
        if ($req->getHeader('date') === null) {
            $req->setHeader('Date', $reqDate); 
        }

        if (!isset($options['headers'])) {
            $options['headers'] = array(); 
        } 
        
        if (!in_array('Date', $options['headers'])) {
            $options['headers'][]= 'Date'; 
        }
        if (!in_array('X-Hmac-Nonce', $options['headers'])) {
            $options['headers'][]= 'X-Hmac-Nonce'; 
        }
        $req->setHeader('X-HMAC-Date', $reqDate); 
        $req->setHeader('X-HMAC-Nonce', 'Thohn2Mohd2zugoo');

        $headersToSign = array();
        foreach($options['headers'] as $hdr) {
            $headersToSign[$hdr] = $req->getHeader($hdr); 
        } 
        
        if (!isset($options['algorithm']))
            $options['algorithm'] = 'sha512';
        $options['algorithm'] = strtolower($options['algorithm']);

        if (!in_array($options['algorithm'], $algorithms))
            throw new \Exception($options['algorithm']." is not supported");

        $canonicalRepresentation = HmacUtils::createCanonicalRepresentation($req->getMethod(), $headersToSign, $req->getUrl());
        $signature = HmacUtils::computeSignature($canonicalRepresentation, $options['secret'], $options['algorithm']);
        //$logger->debug('Canonical Representation ', array($canonicalRepresentation, $signature)); 
        $req->setHeader('Authorization', $options['algorithm'].' '.$options['key'].' '.$signature);
    }
908658
public function onPostCmdEvent(Event $event) {
    // Only install the template files if acquia/blt was installed.
    if (isset($this->bltPackage)) {
      $version = $this->bltPackage->getVersion();
      $this->executeBltUpdate($version);
    }
  }
412138
public function sendEvent(Event $event)
    {
        try {
            $this->eventFactory->addDefaultTagsToEntity($event);
            $this->sendEventThroughSenders($event);
        } catch (\Exception $exception) {
            $this->logException($exception);
        }
    }
1152066
public static function onBeforeSave(Event $event)
    {
        $layout = $event->getTarget();
        if (!is_a($layout, 'BackBee\Site\Layout')) {
            return;
        }

        $dispatcher = $event->getDispatcher();
        if (null !== $dispatcher->getApplication()) {
            if (is_a($event->getEventArgs(), 'Doctrine\ORM\Event\PreUpdateEventArgs')) {
                if (!$event->getEventArgs()->hasChangedField('_data')) {
                    return;
                }
            }

            // Update the layout thumbnail - Beware of generate thumbnail before any other operation
            $thumb = $dispatcher->getApplication()->getEntityManager()
                    ->getRepository('BackBee\Site\Layout')
                    ->generateThumbnail($layout, $dispatcher->getApplication());

            // Update the layout file
            try {
                $dispatcher->getApplication()->getRenderer()->updateLayout($layout);
            } catch (\BackBee\Renderer\Exception\RendererException $e) {
                $dispatcher->getApplication()->warning($e->getMessage());
            }

            if (is_a($event->getEventArgs(), 'Doctrine\ORM\Event\PreUpdateEventArgs')) {
                if ($event->getEventArgs()->hasChangedField('_picpath')) {
                    $event->getEventArgs()->setNewValue('_picpath', $thumb);
                }
            }
        }
    }
478041
public function beforeRender(Event $event)
    {
        $this->httpStatusCode = $this->response->getStatusCode();

        $messageArr = $this->response->withStatus($this->httpStatusCode);

        if (Configure::read('ApiRequest.debug') && isset($this->viewVars['error'])) {
            $this->apiResponse[$this->responseFormat['messageKey']] = $this->viewVars['error']->getMessage();
        } else {
            $this->apiResponse[$this->responseFormat['messageKey']] = !empty($messageArr[$this->httpStatusCode]) ? $messageArr[$this->httpStatusCode] : 'Unknown error!';
        }

        Configure::write('apiExceptionMessage', isset($this->viewVars['error']) ? $this->viewVars['error']->getMessage() : null);

        parent::beforeRender($event);

        $this->viewBuilder()->setClassName('RestApi.ApiError');

        return null;
    }