public function invoke(MethodInvocation $invocation) { $resource = $invocation->getThis(); $result = $invocation->proceed(); $annotation = $this->reader->getMethodAnnotation($invocation->getMethod(), Annotation\ResourceDelegate::class); if (isset($annotation)) { $class = $this->getDelegateClassName($annotation, $resource); if (!class_exists($class)) { throw new InvalidAnnotationException('Resource Delegate class is not found.'); } $method = isset($resource->uri->query['_override']) ? $resource->uri->query['_override'] : $resource->uri->method; if (stripos($method, $resource->uri->method) !== 0) { throw new InvalidMatcherException('Overriden method must match to original method'); } $call = $this->resolveDelegateMethod($method); if (!method_exists($class, $call)) { throw new InvalidMatcherException('Resource Delegate method is not found'); } $delegate = new $class($resource); $params = $this->paramHandler->getParameters([$delegate, $call], $resource->uri->query); return call_user_func_array([$delegate, $call], $params); } else { $result; } }
public function invoke(MethodInvocation $invocation) { $user = $this->session->get('user'); $object = $invocation->getThis(); $object->setUserId($user['id']); return $invocation->proceed(); }
/** * (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(); }
/** * {@inheritdoc} */ public function invoke(MethodInvocation $invocation) { $object = $invocation->getThis(); $auth = $this->auth->start(); $object->body['auth'] = $auth; $result = $invocation->proceed(); return $result; }
public function invoke(MethodInvocation $invocation) { $object = $invocation->getThis(); $user = $this->session->get('user'); if ($this->isAccessDenied($object->uri, $user)) { return $this->resource->get->uri('app://spout/exceptions/accessdenied')->eager->request(); } return $invocation->proceed(); }
/** * {@inheritdoc} */ public function invoke(MethodInvocation $invocation) { $object = $invocation->getThis(); if (!method_exists($object, 'getDbConnection')) { throw new \RuntimeException('The object needs to implement getDbConnection'); } $object->getDbConnection()->transactional(function () use(&$result, $invocation) { $result = $invocation->proceed(); }); return $result; }
/** * (non-PHPdoc) * @see Ray\Aop.MethodInterceptor::invoke() */ public function invoke(MethodInvocation $invocation) { if (is_writable($this->tmpDir)) { return $invocation->proceed(); } $pageObject = $invocation->getThis(); /** @noinspection PhpUnusedLocalVariableInspection */ $tmpDir = $this->tmpDir; $pageObject->view = (include __DIR__ . '/Checker/error.php'); return $pageObject; }
/** * 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(); }
/** * (non-PHPdoc) * @see Ray\Aop.MethodInterceptor::invoke() */ public function invoke(MethodInvocation $invocation) { $object = $invocation->getThis(); $method = $invocation->getMethod(); $connectionParams = $method->name !== 'onGet' ? $this->slaveDb : $this->masterDb; $pagerAnnotation = $this->reader->getMethodAnnotation($method, 'BEAR\\Sunday\\Annotation\\DbPager'); if ($pagerAnnotation) { $connectionParams['wrapperClass'] = 'BEAR\\Package\\Module\\Database\\DoctrineDbalModule\\Connection'; $db = DriverManager::getConnection($connectionParams); $db->setMaxPerPage($pagerAnnotation->limit); } else { $db = DriverManager::getConnection($connectionParams); } /* @var $db \BEAR\Package\Module\Database\DoctrineDbalModule\Connection */ if ($this->sqlLogger instanceof SQLLogger) { $db->getConfiguration()->setSQLLogger($this->sqlLogger); } $object->setDb($db); $result = $invocation->proceed(); if ($this->sqlLogger instanceof SQLLogger) { $this->sqlLogger->stopQuery(); $object->headers['x-sql'] = [$this->sqlLogger->queries]; } if ($pagerAnnotation) { $pagerData = $db->getPager(); if ($pagerData) { $object->headers['pager'] = $pagerData; } } return $result; }
public function invoke(MethodInvocation $invocation) { $result = $invocation->proceed(); file_put_contents(sprintf('%s/var/log/resource.%d.log', dirname(dirname(__DIR__)), date('Ymd')), sprintf("[%s]\n%s\n\n", date('H:i:s'), var_export(['resource' => (array) $invocation->getThis()->uri, 'result' => $result, 'body' => file_get_contents('php://input'), 'server' => $_SERVER, 'get' => $_GET, 'post' => $_POST], true)), FILE_APPEND); return $result; }
/** * {@inheritdoc} */ public function invoke(MethodInvocation $invocation) { $object = $invocation->getThis(); $method = $invocation->getMethod(); $write = ['onPut', 'onDelete', 'onPost']; $connectionParams = in_array($method->name, $write) ? $this->masterDb : $this->slaveDb; $pagerAnnotation = $this->reader->getMethodAnnotation($method, 'BEAR\\Sunday\\Annotation\\DbPager'); $db = $this->getDb($pagerAnnotation, $connectionParams); /* @var $db \BEAR\Package\Module\Database\Dbal\PagerConnection */ if ($this->sqlLogger instanceof SQLLogger) { $db->getConfiguration()->setSQLLogger($this->sqlLogger); } $object->setDb($db); $result = $invocation->proceed(); if ($this->sqlLogger instanceof DebugStack) { $this->sqlLogger->stopQuery(); $object->headers['x-sql'] = [$this->sqlLogger->queries]; } elseif ($this->sqlLogger instanceof SQLLogger) { $this->sqlLogger->stopQuery(); } if (!$pagerAnnotation) { return $result; } $pagerData = $db->getPager(); if ($pagerData) { $object->headers['pager'] = $pagerData; } return $result; }