Fetching invocation context.

@param int $invocationTID
@param int $argumentsTID

@return array
331918
private function fetchContext(int $invocationTID, int $argumentsTID): array
    {
        $class = $operator = '';
        $name = trim($this->getSource($invocationTID, $argumentsTID), '( ');

        //Let's try to fetch all information we need
        if (strpos($name, '->') !== false) {
            $operator = '->';
        } elseif (strpos($name, '::') !== false) {
            $operator = '::';
        }

        if (!empty($operator)) {
            list($class, $name) = explode($operator, $name);

            //We now have to clarify class name
            if (in_array($class, ['self', 'static', '$this'])) {
                $class = $this->activeDeclaration($invocationTID);
            }
        }

        return [$class, $operator, $name];
    }
113190
public static function get_contexts_for_userid(int $userid) : contextlist {
        $contextlist = new contextlist();
        $contextlist->add_from_sql("SELECT c.id
                  FROM {context} c
                  JOIN {tag} t ON t.userid = :userid
                 WHERE contextlevel = :contextlevel",
            ['userid' => $userid, 'contextlevel' => CONTEXT_SYSTEM]);
        return $contextlist;
    }
636533
private function getServiceCallsFromArguments(array $arguments, array &$calls, $isPreInstance, $callerId, array &$behavior = array(), $step = 1)
    {
        foreach ($arguments as $argument) {
            if (is_array($argument)) {
                $this->getServiceCallsFromArguments($argument, $calls, $isPreInstance, $callerId, $behavior, $step);
            } elseif ($argument instanceof Reference) {
                $id = $this->container->normalizeId($argument);

                if (!isset($calls[$id])) {
                    $calls[$id] = (int) ($isPreInstance && isset($this->circularReferences[$callerId][$id]));
                }
                if (!isset($behavior[$id])) {
                    $behavior[$id] = $argument->getInvalidBehavior();
                } else {
                    $behavior[$id] = min($behavior[$id], $argument->getInvalidBehavior());
                }

                $calls[$id] += $step;
            }
        }
    }
1074397
protected function queryLogFormatter(
        QueryLog $annotation,
        MethodInvocation $invocation
    ): array {
        return [
            'level'   => $annotation->value,
            'message' => sprintf(
                $this->format,
                $annotation->name,
                $invocation->getMethod()->class,
                $invocation->getMethod()->name
            ),
            'context' => [
                'queries' => $this->queryLogs,
            ],
        ];
    }
779699
@Override
    public CRLReason getRevocationReason() {
        Extension ext = getExtension(PKIXExtensions.ReasonCode_Id);
        if (ext == null) {
            return null;
        }
        CRLReasonCodeExtension rcExt = (CRLReasonCodeExtension) ext;
        return rcExt.getReasonCode();
    }
839
public function invokeWithin($fn, $args = array())
    {
        $this->invocation_context->activate();

        $this->invocation_context->push($this);
        try {
            $result = call_user_func_array($fn, $args);
            $this->invocation_context->pop();
            $this->invocation_context->deactivate();
            return $result;
        } catch (\Exception $e) {
            $this->invocation_context->pop();
            $this->invocation_context->deactivate();
            throw $e;
        }
    }
300759
public function setInvocation(Invocation $invocation)
    {
        $this->invocation = $invocation;

        $this->setAttachments($invocation->getAttachments());
    }
308038
public function get_instance_context(int $instanceid = 0) : \context {
        if ($instanceid > 0) {
            return \context_course::instance($instanceid);
        } else {
            return \context_system::instance();
        }
    }
1078299
protected function generateCacheName($name, MethodInvocation $invocation): array
    {
        if (is_array($name)) {
            throw new \InvalidArgumentException('Invalid argument');
        }
        if (is_null($name)) {
            $name = $invocation->getMethod()->name;
        }

        return [$name];
    }
1242235
protected function doInvoke(Invocation $invocation)
    {
        return (new Pipeline($this->container))
            ->send($invocation)
            ->through($this->middleware)
            ->then(function ($invocation) {
                return $this->invoker->invoke($invocation);
            });
    }
1365184
public function invoke(MethodInvocation $invocation)
    {
        /** @var RetryOnFailure $annotation */
        $annotation = $invocation->getMethod()->getAnnotation($this->annotation);
        $key = $this->keyName($invocation);

        if (isset(self::$attempt[$key]) === false) {
            self::$attempt[$key] = $annotation->attempts;
        }

        try {
            self::$attempt[$key]--;

            return $invocation->proceed();
        } catch (\Exception $e) {
            if (ltrim($annotation->ignore, '\\') === get_class($e)) {
                self::$attempt[$key] = null;
                throw $e;
            }

            $pass = array_filter($annotation->types, function ($values) use ($e) {
                return ltrim($values, '\\') === get_class($e);
            });
            if ($pass !== false) {
                if (self::$attempt[$key] > 0) {
                    sleep($annotation->delay);

                    return $invocation->proceed();
                }
            }
            self::$attempt[$key] = null;
            throw $e;
        }
    }
859058
public function invoke(MethodInvocation $invocation)
    {
        /** @var \Ytake\LaravelAspect\Annotation\Loggable $annotation */
        $annotation = $invocation->getMethod()->getAnnotation($this->annotation);
        $start = microtime(true);
        $result = $invocation->proceed();
        $time = number_format(microtime(true) - $start, 15);
        $logFormat = $this->logFormatter($annotation, $invocation);
        $logger = static::$logger;
        if (!$annotation->skipResult) {
            $logFormat['context']['result'] = $result;
        }
        $logFormat['context']['time'] = $time;
        /** Monolog\Logger */
        if ($logger instanceof LogManager) {
            if (!is_null($annotation->driver)) {
                $logger = $logger->driver($annotation->driver);
            }
            $logger->addRecord($logFormat['level'], $logFormat['message'], $logFormat['context']);
        }

        return $result;
    }
333367
public function invoke(MethodInvocation $invocation)
    {
        /** @var MessageDriven $annotation */
        $annotation = $invocation->getMethod()->getAnnotation($this->annotation);
        $command = new EagerMessage($invocation);
        if ($annotation->value instanceof LazyQueue) {
            $command = new LazyMessage($invocation);
            $command->onQueue($annotation->onQueue)
                ->delay($annotation->value->delay())
                ->onConnection($annotation->mappedName);
        }

        return static::$dispatcher->dispatch($command);
    }
878900
public function getApplicationArguments(string $applicationId): array
    {
        if (!isset($this->applications[$applicationId])) {
            throw new \UnexpectedValueException('Unexpected application id: ' . $applicationId);
        }
        return $this->applications[$applicationId]['arguments'] ?? [];
    }
282609
public function indexInvocations(InvocationsInterface $locator)
    {
        $this->registerInvocations($locator->getInvocations(
            new \ReflectionFunction('l')
        ));

        $this->registerInvocations($locator->getInvocations(
            new \ReflectionFunction('p')
        ));

        $this->registerInvocations($locator->getInvocations(
            new \ReflectionMethod(TranslatorTrait::class, 'say')
        ));
    }
999172
public function fetchTopic($guid, $options = [])
    {
        $options['guid'] = $guid;
        return $this->_request(self::FETCH_TOPIC, $options);
    }
106048
private function resolveArgumentsFromMethodCall(Return_ $returnNode): array
    {
        $arguments = [];
        if ($returnNode->expr instanceof MethodCall) {
            foreach ($returnNode->expr->args as $arg) {
                if ($arg->value instanceof Array_) {
                    $arguments[] = $arg->value;
                }
            }
        }

        return $arguments;
    }