public function preHook()

in agent/php/ElasticApm/Impl/AutoInstrument/WordPressAutoInstrumentation.php [400:445]


    public function preHook(?string $instrumentedClassFullName, string $instrumentedFunction, array $capturedArgs): ?callable
    {
        if ($this->isInFailedMode) {
            return null /* <- null means there is no post-hook */;
        }

        $logger = $this->logger->inherit()->addAllContext(
            ['instrumentedClassFullName' => $instrumentedClassFullName, 'instrumentedFunction' => $instrumentedFunction, 'capturedArgs' => $capturedArgs]
        );

        // We should cover all the function instrumented in src/ext/WordPress_instrumentation.c

        if ($instrumentedClassFullName !== null) {
            if ($instrumentedClassFullName !== 'WP_Hook') {
                ($loggerProxy = $logger->ifErrorLevelEnabled(__LINE__, __FUNCTION__)) && $loggerProxy->log('Unexpected instrumentedClassFullName');
                $this->switchToFailedMode();
                return null /* <- null means there is no post-hook */;
            }
            if ($instrumentedFunction !== 'add_filter') {
                ($loggerProxy = $logger->ifErrorLevelEnabled(__LINE__, __FUNCTION__)) && $loggerProxy->log('Unexpected instrumentedFunction');
                $this->switchToFailedMode();
                return null /* <- null means there is no post-hook */;
            }

            $this->preHookAddFilter($capturedArgs);
            return null /* <- null means there is no post-hook */;
        }

        switch ($instrumentedFunction) {
            case '_wp_filter_build_unique_id':
                $this->preHookWpFilterBuildUniqueId($capturedArgs);
                return null /* <- null means there is no post-hook */;
            case 'get_template':
                /**
                 * @param ?Throwable $thrown
                 * @param mixed      $returnValue
                 */
                return function (?Throwable $thrown, $returnValue): void {
                    $this->postHookGetTemplate($thrown, $returnValue);
                };
            default:
                ($loggerProxy = $logger->ifErrorLevelEnabled(__LINE__, __FUNCTION__)) && $loggerProxy->log('Unexpected instrumentedFunction');
                $this->switchToFailedMode();
        }
        return null /* <- null means there is no post-hook */;
    }