/**
  * Method invoker
  *
  * @param $invocation MethodInvocation the method invocation joinpoint
  * @return mixed the result of the call to {@see Joinpoint->proceed()}
  */
 public final function invoke(MethodInvocation $invocation)
 {
     if ($this->pointcut->matches($invocation->getMethod(), $invocation->getThis(), $invocation->getArguments())) {
         return $this->adviceMethod->invoke($invocation);
     }
     return $invocation->proceed();
 }
 /**
  * Converts the given text area into a WYSIWYG editor.
  *
  * @param \Go\Aop\Intercept\MethodInvocation $invocation Invocation
  * @Around("execution(public CMS\View\Helper\FormHelper->textarea(*))")
  * @return bool Whether object invocation should proceed or not
  */
 public function alterTextarea(MethodInvocation $invocation)
 {
     $helper = $invocation->getThis();
     list($fieldName, $options) = array_pad($invocation->getArguments(), 2, null);
     if (!empty($options['class']) && strpos($options['class'], 'ckeditor') !== false && $helper instanceof FormHelper) {
         static::$_counter++;
         $editorId = 'ck-editor-' . static::$_counter;
         $options['class'] .= ' ' . $editorId;
         $view = $this->getProperty($helper, '_View');
         if (!static::$_scriptsLoaded) {
             static::$_scriptsLoaded = true;
             $filebrowserBrowseUrl = $view->Url->build(['plugin' => 'Wysiwyg', 'controller' => 'finder']);
             $view->Html->script('Wysiwyg./ckeditor/ckeditor.js', ['block' => true]);
             $view->Html->script('Wysiwyg./ckeditor/adapters/jquery.js', ['block' => true]);
             $view->Html->scriptBlock('$(document).ready(function () {
                 CKEDITOR.editorConfig = function(config) {
                     config.filebrowserBrowseUrl = "' . $filebrowserBrowseUrl . '";
                 };
             });', ['block' => true]);
             $this->_includeLinksToContents($view);
         }
     }
     $this->setProperty($invocation, 'arguments', [$fieldName, $options]);
     return $invocation->proceed();
 }
 /**
  * @param MethodInvocation $methodInvocation
  *
  * @return void
  *
  * @throws \ErrorException
  */
 public function __invoke(MethodInvocation $methodInvocation)
 {
     $reflectionParameters = $methodInvocation->getMethod()->getParameters();
     $applyTypeChecks = $this->applyTypeChecks;
     foreach ($methodInvocation->getArguments() as $argumentIndex => $argument) {
         $applyTypeChecks($this->getParameterDocblockType(get_class($methodInvocation->getThis()), $reflectionParameters, $argumentIndex), $argument);
     }
 }
 /**
  * Returns an associative list of arguments for the method invocation
  *
  * @param MethodInvocation $invocation
  * @return array
  */
 protected function fetchMethodArguments(MethodInvocation $invocation)
 {
     $parameters = $invocation->getMethod()->getParameters();
     $argumentNames = array_map(function (\ReflectionParameter $parameter) {
         return $parameter->name;
     }, $parameters);
     $parameters = array_combine($argumentNames, $invocation->getArguments());
     return $parameters;
 }
 /**
  * Cacheable methods
  *
  * @param MethodInvocation $invocation Invocation
  *
  * @Go\Lang\Annotation\Around("execution(public Nucleus\Cache\BaseCacheService->set(*))")
  */
 public function arroundSet(MethodInvocation $invocation)
 {
     $arguments = $invocation->getArguments();
     $call = array('method' => 'set', 'name' => $arguments[0], 'namespace' => $arguments[3]);
     $this->getDebugBar()->getCollector('messages')->addMessage('Cache set [' . $arguments[3] . '] / [' . $arguments[0] . ']');
     $result = $invocation->proceed();
     $this->data['calls'][] = $call;
     return $result;
 }
 /**
  * Adds prefix to every input element that may have a "name" attribute.
  *
  * @param \Go\Aop\Intercept\MethodInvocation $invocation Invocation
  * @Around("execution(public Cake\View\Helper\FormHelper->label|input|checkbox|radio|textarea|hidden|file|select|multiCheckbox|day|year|month|hour|minute|meridian|dateTime|time|date(*))")
  * @return bool Whether object invocation should proceed or not
  */
 public function addInputPrefix(MethodInvocation $invocation)
 {
     $helper = $invocation->getThis();
     $args = $invocation->getArguments();
     if (!empty($args[0]) && is_string($args[0]) && $helper instanceof FormHelper) {
         $args[0] = $this->_fieldName($helper, $args[0]);
     }
     $this->setProperty($invocation, 'arguments', $args);
     return $invocation->proceed();
 }
 /**
  *
  * Adds a shortcut button to Comment's management submenu.
  *
  * @param \Go\Aop\Intercept\MethodInvocation $invocation Invocation
  * @Before("execution(public Menu\View\Helper\MenuHelper->render(*))")
  */
 public function commentsNav(MethodInvocation $invocation)
 {
     $helper = $invocation->getThis();
     $settings = plugin('Disqus')->settings;
     list($items, $options) = $invocation->getArguments();
     if (!empty($settings['disqus_shortname']) && count($items) == 5 && $items[0]['title'] == __d('comment', 'All')) {
         $items[] = ['title' => __d('disqus', 'Go to Disqus Moderation'), 'url' => 'https://' . $settings['disqus_shortname'] . '.disqus.com/admin/moderate/', 'target' => '_blank'];
         $this->setProperty($invocation, 'arguments', [$items, $options]);
     }
 }
Exemple #8
0
 /**
  * @param MethodInvocation $invocation Invocation
  * @Before("execution(public Endpoint->call(*))") // This is our PointCut
  */
 public function beforeServiceCall(MethodInvocation $invocation)
 {
     $methodThis = $invocation->getThis();
     $service = $methodThis->service()->first();
     $serviceName = $service->name;
     $serviceLimit = \DB::table('limits')->where('service_id', '=', $service->id)->first();
     \DB::table('limits')->where('service_id', '=', $service->id)->update(array('current_hits' => 0));
     $serviceLimit->current_hits = 0;
     $hasLimitBeenReached = $serviceLimit->current_hits >= $serviceLimit->max_hits;
     if ($hasLimitBeenReached) {
         echo "The limit number of calls for service \"" . $serviceName . "\" have been reached \n";
         echo "Method execution stoped";
         die;
     }
     \DB::table('limits')->where('service_id', '=', $service->id)->update(array('current_hits' => $serviceLimit->current_hits + 1));
     $methodName = $invocation->getMethod()->getName();
     $methodParams = implode(', ', $invocation->getArguments());
     // echo "Calling method " . $methodName . " with params : " . $methodParams . "\n";
     // echo "Method execution continues \n";
     // echo "Method result \n";
 }
 /**
  * This method will check, if user is authorized
  *
  * @param MethodInvocation $invocation
  * @Around("$this->authorizePointcut")
  */
 public function authorize(MethodInvocation $invocation)
 {
     $rflMethod = $invocation->getMethod();
     $type = null;
     $userFactory = null;
     $expression = null;
     $resourceFactory = null;
     $resourceFactoryAdditionalParameters = null;
     $policies = array();
     foreach ($rflMethod->getAnnotations() as $annotation) {
         switch ($annotation) {
             case $annotation instanceof AuthorizationSecurity:
                 $type = $annotation->securityTypeName();
                 $userFactory = $annotation->userFactoryName();
                 break;
             case $annotation instanceof AuthorizationExpression:
                 $expression = $annotation->expression();
                 break;
             case $annotation instanceof AuthorizationResourceFactory:
                 $resourceFactory = $annotation->resourceFactoryName();
                 $resourceFactoryAdditionalParameters = $annotation->additionalParameters();
                 break;
             case $annotation instanceof AuthorizationPolicy:
                 $policies[] = $annotation->policyName();
                 break;
         }
     }
     /** @var Security $securityAPI */
     $securityAPI = DIContainer::getInstance()->get('security');
     if (!is_null($resourceFactory)) {
         /** @var ResourceFactory $userFactory */
         $resourceFactoryForArguments = DIContainer::getInstance()->getResourceFactory($resourceFactory);
         $resourceFactoryForArguments->setArguments($invocation->getArguments());
         $resourceFactoryForArguments->setAdditionalParameters($resourceFactoryAdditionalParameters);
     }
     $securityCommand = new SecurityCommand($type, $userFactory, $expression, $resourceFactory, $policies);
     $securityAPI->authorize($securityCommand);
     $invocation->proceed();
 }
 /**
  * This advice intercepts an execution of methods via __callStatic
  *
  * @param MethodInvocation $invocation
  * @Before("dynamic(public Demo\Example\DynamicMethodsDemo::find*(*))")
  */
 public function beforeMagicStaticMethodExecution(MethodInvocation $invocation)
 {
     // we need to unpack args from invocation args
     list($methodName) = $invocation->getArguments();
     echo "Calling Magic Static Interceptor for method: ", $methodName, PHP_EOL;
 }
Exemple #11
0
 /**
  * Method that should be called before real method
  *
  * @param MethodInvocation $invocation Invocation
  * @Before("within(**)")
  */
 public function beforeMethodExecution(MethodInvocation $invocation)
 {
     $obj = $invocation->getThis();
     echo 'Calling Before Interceptor for method: ', is_object($obj) ? get_class($obj) : $obj, $invocation->getMethod()->isStatic() ? '::' : '->', $invocation->getMethod()->getName(), '()', ' with arguments: ', json_encode($invocation->getArguments()), "<br>\n";
 }
 /**
  * This advice intercepts an execution of loggable methods
  *
  * We use "Before" type of advice to log only class name, method name and arguments before
  * method execution.
  * You can choose your own logger, for example, monolog or log4php.
  * Also you can choose "After" or "Around" advice to access an return value from method.
  *
  * To inject logger into this aspect you can look at Warlock framework with DI+AOP
  *
  * @param MethodInvocation $invocation Invocation
  *
  * @Before("@execution(Demo\Annotation\Loggable)")
  */
 public function beforeMethodExecution(MethodInvocation $invocation)
 {
     echo 'Calling Before Interceptor for ', $invocation, ' with arguments: ', json_encode($invocation->getArguments()), PHP_EOL;
 }
 /**
  * @param MethodInvocation $invocation Invocation
  *
  * @Go\Lang\Annotation\Around("execution(public Kohana_Request_Client_Internal->execute_request(*))")
  */
 public function aroundKohanaRequestClientInternalExecuteRequest(MethodInvocation $invocation)
 {
     $arguments = $invocation->getArguments();
     $kohanaRequest = $arguments[0];
     /* @var $kohanaRequest \Request */
     $kohanaParameters = $kohanaRequest->param();
     $request = $this->createNucleusRequest($kohanaRequest, $kohanaParameters);
     //We do this now so a controller in kohana can generate route properly from nucleus
     $this->getRouter()->setCurrentRequest($request);
     if (!isset($kohanaParameters['_nucleus'])) {
         return $invocation->proceed();
     }
     $previousKohanaRequest = KohanaRequest::$current;
     KohanaRequest::$current = $kohanaRequest;
     $request->request->add($kohanaParameters['_nucleus']);
     $service = $request->request->get('_service');
     $response = $this->getFrontController()->execute($service['name'], $service['method'], $request);
     $kohanaResponse = $kohanaRequest->create_response();
     $this->mergeResponse($kohanaResponse, $response);
     KohanaRequest::$current = $previousKohanaRequest;
     return $kohanaResponse;
 }
Exemple #14
0
 private function getCacheEntryNameFromString(MethodInvocation $invocation, $name)
 {
     $arguments = $invocation->getArguments();
     $replaces = array();
     foreach ($invocation->getMethod()->getParameters() as $parameter) {
         /* @var $parameter \ReflectionParameter */
         $replaces['$' . $parameter->getName()] = serialize($arguments[$parameter->getPosition()]);
     }
     return str_replace(array_keys($replaces), array_values($replaces), $name);
 }