On before event handler

@return array
@throws \InvalidArgumentException
195576
public function onBefore(BeforeEvent $event)
    {
        $now       = new \DateTime;
        $createdAt = $now->format($this->getDateFormat());
        $request   = $event->getRequest();
        $nonce     = call_user_func($this->getNonce(), $request);
        $password  = $this->passwordProcessor ? call_user_func($this->passwordProcessor, $this->password) : $this->password;
        $digest    = call_user_func($this->getDigest(), $nonce, $createdAt, $password);

        $request->setHeader('Authorization', 'WSSE profile="UsernameToken"');
        $request->setHeader(
            'X-WSSE',
            $this->createWsseHeader(
                $this->username,
                $digest,
                $nonce,
                $createdAt
            )
        );
    }
1261241
private function renderPreviousButton()
    {
        $before = $this->page->before;
        $extraClass = $before ? '' : ' not-active';
        if (empty($before)) {
            $before = 1;
        }
        return $this->renderElement($before, $this->settings['label_previous'], 'prev'.$extraClass);
    }
1343944
public function beforeFilter() {
        if(!isset($this->_beforeFilters[$this->_action])) {
            return false;
        }

        foreach($this->_beforeFilters[$this->_action] as $method) {
            call_user_func($method);
        }
    }
771089
protected function createBeforeFilter() {
    $before = $this->before;

    // closure that iterates over all before filters
    return function ($request) use ($before) {
      foreach ($before as $filter) {
        $response = $filter->onBefore($request);
        if (!is_null($response)) {
          return $response;
        }
      }

      return null;
    };
  }
611992
public function onBeforeWrite()
    {
        $fieldMap = json_decode($this->SpamFieldSettings, true);
        if (empty($fieldMap)) {
            $fieldMap = array();
        }

        foreach ($this->record as $key => $value) {
            if (substr($key, 0, 8) === 'spammap-') {
                $fieldMap[substr($key, 8)] = $value;
            }
        }
        $this->setField('SpamFieldSettings', json_encode($fieldMap));

        return parent::onBeforeWrite();
    }
1012513
public function onPageRendering(BeforePageRenderingEvent $event)
    {
        $response = $event->getResponse();

        $slotContents = $this->renderSlotContents();
        
        if (!is_array($slotContents)) {
            throw new \InvalidArgumentException('"renderSlotContents" method must return an array');
        }

        foreach ($slotContents as $slotContent) {
            $this->renderSlot($response, $slotContent);
        }

        $event->setResponse($response);
    }
818867
public function beforeRender()
    {
        if (!$this->_actionCheck()) {
            return null;
        }

        $controller = $this->_registry->getController();
        $modelClass = $this->getConfig('modelClass', $controller->modelClass);
        if (!$modelClass) {
            return null;
        }

        list (, $modelName) = pluginSplit($modelClass);
        if (!isset($controller->{$modelName})) {
            return null;
        }

        /* @var \Cake\ORM\Table|\Search\Model\Behavior\SearchBehavior $model */
        $model = $controller->{$modelName};
        if (!$model->behaviors()->has('Search')) {
            return null;
        }

        $controller->set('_isSearch', $model->isSearch());
        $controller->set('_searchParams', $model->searchParams());
    }
10223
public function beforeRender(Event $event): void
    {
        $this->setJson('isAjax', $this->_controller->request->is('ajax'));
        $this->setJson('isMobile', $this->_controller->request->is('mobile'));
        $this->setBoth('isDialog', $this->_controller->request->is('dialog'));
        $this->setBoth('isJson', $this->_controller->request->is('json'));
        $this->setJson('debug', Configure::read('debug'));

        $ssl = false;
        if (env('HTTPS') || $this->_controller->request->is('ssl') || $this->_controller->request->env('HTTP_X_FORWARDED_PROTO') == 'https') {
            $ssl = true;
        }

        $appData = array(
            'jsonData' => $this->_jsonData,
            'webroot' => 'http' . ($ssl ? 's' : '') . '://' . env('HTTP_HOST') . $this->_controller->request->webroot,
            'url' => $this->_controller->request->url,
            // 'controller' => $this->_controller->name,
            // 'action' => $this->_controller->request->action,
            // 'plugin' => $this->_controller->request->plugin,
            'request' => array(
                'query' => $this->_controller->request->query,
                'pass' => $this->_controller->request->params['pass'],
                'plugin' => $this->_controller->request->plugin,
                'controller' => Inflector::underscore($this->_controller->name),
                'action' => $this->_controller->request->action
            )
        );

        // merge in the additional frontend data
        $appData = Hash::merge($appData, $this->_additionalAppData);
        $this->_controller->set('frontendData', $appData);
        $this->_controller->set('closeDialog', $this->_closeDialog);
    }
587356
protected function _handlers()
    {
        $gmstrtotime = function ($value) {
            $TZ = date_default_timezone_get();
            if ($TZ === 'UTC') {
                return strtotime($value);
            }
            date_default_timezone_set('UTC');
            $time = strtotime($value);
            date_default_timezone_set($TZ);
            return $time;
        };

        return [
            'array' => [
                'object' => function($value, $column) {
                    return $value->to('array', $column);
                },
                'string' => function($value, $column) {
                    return (string) $value;
                },
                'integer' => function($value, $column) {
                    return (int) $value;
                },
                'float' => function($value, $column) {
                    return (float) $value;
                },
                'date' => function($value, $column) {
                    return $this->convert('array', 'datetime', $value, ['format' => 'Y-m-d']);
                },
                'datetime' => function($value, $column) use ($gmstrtotime) {
                    $column += ['format' => 'Y-m-d H:i:s'];
                    $format = $column['format'];
                    if ($value instanceof DateTime) {
                        return $value->format($format);
                    }
                    return gmdate($format, is_numeric($value) ? $value : $gmstrtotime($value));
                },
                'boolean' => function($value, $column) {
                    return $value;
                },
                'null' => function($value, $column) {
                    return;
                },
                'json' => function($value, $column) {
                    return is_array($value) ? $value : $value->to('array', $column);
                }
            ],
            'cast' => [
                'object' => function($value, $column, $options) {
                    return is_array($value) ? new Document([
                        'schema' => $options['schema'] ?? null,
                        'basePath' => $options['basePath'] ?? null,
                        'data' => $value
                    ]) : $value;
                },
                'string' => function($value, $column, $options) {
                    return (string) $value;
                },
                'integer' => function($value, $column, $options) {
                    return (integer) $value;
                },
                'float'   => function($value, $column, $options) {
                    return (float) $value;
                },
                'decimal' => function($value, $column, $options) {
                    $column += ['precision' => 2, 'decimal' => '.', 'separator' => ''];
                    return number_format($value, $column['precision'], $column['decimal'], $column['separator']);
                },
                'boolean' => function($value, $column, $options) {
                    return !!$value;
                },
                'date'    => function($value, $column, $options) {
                    return $this->convert('cast', 'datetime', $value, ['format' => 'Y-m-d'], $options);
                },
                'datetime'    => function($value, $column, $options) use ($gmstrtotime) {
                    $column += ['format' => 'Y-m-d H:i:s'];
                    if ($value instanceof DateTime) {
                        return $value;
                    }
                    $timestamp = is_numeric($value) ? $value : $gmstrtotime($value);
                    if ($timestamp < 0 || $timestamp === false) {
                        return;
                    }
                    return DateTime::createFromFormat("!{$column['format']}", gmdate($column['format'], $timestamp), new DateTimeZone('UTC'));
                },
                'null'    => function($value, $column, $options) {
                    return null;
                },
                'json' => function($value, $column, $options) {
                    return is_string($value) ? json_decode($value, true) : $value;
                }
            ]
        ];
    }
995979
protected function beforeCreate()
    {
        $this->dispatcher->getEventsManager()->fire(Events::BEFORE_CREATE, $this);
        $this->beforeSave();
    }
799577
protected function defaultHandler()/*# : bool */
    {
        $status = $this->result->getStatus();
        $handler = $this->result->getHandler() ?: $this->getHandler($status);

        if ($handler) {
            $param = ['result' => $this->result];
            $callable = $this->getResolver()->resolve($handler);
            if ($this->trigger(self::EVENT_BEFORE_HANDLER, $param)) {
                call_user_func($callable, $this->result);
                $this->trigger(self::EVENT_AFTER_HANDLER, $param);
            }
        }
        return false;
    }
718508
public function beforeException() {
        /**
         * @param \Phalcon\Events\Event $event
         * @param \Phalcon\Dispatcher $dispatcher
         * @param \Exception $exception
         * @return callable
         */
        return function(Event $event, Dispatcher $dispatcher, \Exception $exception) {
            $resolver = new ExceptionResolver();
            $resolver->setDI($dispatcher->getDI());
            $resolver->resolve($exception);

            return false;
        };
    }
918571
public static function getEventListeners()
    {
        $listeners = array();

        $reflection = new ReflectionClass(get_called_class());
        foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method)
        {
            if(substr($method->name, 0, 2) == 'on') {
               $listeners[] = $method->name;
            }
        }

        return $listeners;
    }
1015730
public function events()
    {
        return [
            \yii\db\ActiveRecord::EVENT_BEFORE_VALIDATE => 'handleValidate',
            \yii\db\ActiveRecord::EVENT_AFTER_INSERT => 'handleAfterSave',
            \yii\db\ActiveRecord::EVENT_AFTER_UPDATE => 'handleAfterSave',
        ];
    }
91819
public function prevEvent()
    {
        $prev = $this->eventManager()->prev();

        if (!$prev) {
            return null;
        }

        return $this->eventFormatNav($prev);
    }
976854
public function onBefore(BeforeEvent $event)
    {
        $request = $event->getRequest();
        if ($request->getConfig()->get('auth') == 'oauth2') {
            $token = $this->getAccessToken();
            if ($token !== null) {
                $request->setHeader('Authorization', 'Bearer ' . $token->getToken());
            }
        }
    }
145850
public function beforeDetach()
    {
        $handler = $this->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->beforeDetach($this);
        }
    }