/** * (non-PHPdoc) * @see Ray\Aop.MethodInterceptor::invoke() */ public function invoke(MethodInvocation $invocation) { // retrieve page and query $args = $invocation->getArguments(); $page = $invocation->getThis(); // strip tags foreach ($args as &$arg) { $arg = strip_tags($arg); } // required title if ($args[self::TITLE] === '') { $this->errors['title'] = 'title required.'; } // required body if ($args[self::BODY] === '') { $this->errors['body'] = 'body required.'; } // valid form ? if (implode('', $this->errors) === '') { return $invocation->proceed(); } // error, modify 'GET' page wih error message. $page['errors'] = $this->errors; $page['submit'] = ['title' => $args[self::TITLE], 'body' => $args[self::BODY]]; return $page->onGet(); }
public function invoke(MethodInvocation $invocation) { (array) ($args = $invocation->getArguments()); $validator = $this->validator; $method = $invocation->getMethod()->name; $id = $method == 'onPut' ? $args[self::ID] : null; if (!$validator->get('emailaddress')->isValid($args[self::EMAIL])) { $this->errors['email'] = $validator->getMessages()[0]; } if (!$validator->get('notempty')->isValid($args[self::NAME])) { $this->errors['name'] = $validator->getMessages()[0]; } if (!$validator->get('notempty')->isValid($args[self::ROLE]['id'])) { $this->errors['role'] = $validator->getMessages()[0]; } if ($method == 'onPost' && !$validator->get('notempty')->isValid($args[self::PASSWORD])) { $this->errors['password'] = $validator->getMessages()[0]; } if (!isset($this->errors['email']) && !$this->isUniqueEmail($args[self::EMAIL], $id)) { $this->errors['email'] = 'Email address already exists.'; } if (implode('', $this->errors) == '') { return $invocation->proceed(); } return $this->resource->get->uri('app://spout/exceptions/validation')->withQuery(['errors' => $this->errors])->eager->request(); }
/** * @param LoggableAnnotate $annotation * @param MethodInvocation $invocation * * @return string[] */ protected function logFormatter(LoggableAnnotate $annotation, MethodInvocation $invocation) { $context = []; $arguments = $invocation->getArguments(); foreach ($invocation->getMethod()->getParameters() as $parameter) { $context['args'][$parameter->name] = $arguments[$parameter->getPosition()]; } return ['level' => $annotation->value, 'message' => sprintf($this->format, $annotation->name, $invocation->getMethod()->class, $invocation->getMethod()->name), 'context' => $context]; }
/** * Intercepts any method and injects instances of the missing arguments * when they are type hinted */ public function invoke(MethodInvocation $invocation) { $object = $invocation->getThis(); $parameters = $invocation->getMethod()->getParameters(); $arguments = $invocation->getArguments()->getArrayCopy(); $assisted = []; foreach ($parameters as $k => $p) { $hint = $p->getClass(); if ($hint) { $assisted[$k] = PipingBag::get($hint->getName()); continue; } if (isset($arguments[$k])) { $assisted[$k] = array_shift($arguments); continue; } $assisted[$k] = $p->getDefaultValue(); } $invocation->getArguments()->exchangeArray($assisted); return $invocation->proceed(); }
/** * {@inheritdoc} */ public function get(MethodInvocation $invocation) { $args = $invocation->getArguments()->getArrayCopy(); $params = $invocation->getMethod()->getParameters(); $namedArgs = []; foreach ($params as $param) { if (isset($namedArgs[$param->name])) { throw new DuplicatedNamedParam($param->name); } $namedArgs[$param->name] = array_shift($args); } return $namedArgs; }
/** * @param MethodInvocation $invocation * @param $annotation * @param $keys * * @return array */ protected function detectCacheKeys(MethodInvocation $invocation, $annotation, $keys) { $arguments = $invocation->getArguments(); foreach ($invocation->getMethod()->getParameters() as $parameter) { // exclude object if (in_array('#' . $parameter->name, $annotation->key)) { if (isset($arguments[$parameter->getPosition()])) { if (!is_object($arguments[$parameter->getPosition()])) { $keys[] = $arguments[$parameter->getPosition()]; } } if (!isset($arguments[$parameter->getPosition()])) { $keys[] = $parameter->getDefaultValue(); } } } return $keys; }
public function invoke(MethodInvocation $invocation) { (array) ($args = $invocation->getArguments()); $validator = $this->validator; $method = $invocation->getMethod()->name; $id = $method == 'onPut' ? $args[self::ID] : null; if (!$validator->get('notempty')->isValid($args[self::TITLE])) { $this->errors['title'] = $validator->getMessages()[0]; } if (!$validator->get('notempty')->isValid($args[self::TYPE]['id'])) { $this->errors['type'] = $validator->getMessages()[0]; } if (!$validator->get('notempty')->isValid($args[self::TYPE]['id'])) { $this->errors['type'] = $validator->getMessages()[0]; } if (empty($this->errors) && !$this->isUniqueResourceName($args[self::TYPE]['slug'], $args[self::SLUG], $id)) { $this->errors['slug'] = 'The slug has already been taken for this media type.'; } if (implode('', $this->errors) == '') { return $invocation->proceed(); } return $this->resource->get->uri('app://spout/exceptions/validation')->withQuery(['errors' => $this->errors])->eager->request(); }