createMethodGenerator example

$classGenerator->setImplementedInterfaces([
            Enlight_Hook_Proxy::class,
        ]);

        // Add the private '__hookProxyExecutionContexts' array property         $classGenerator->addProperty('__hookProxyExecutionContexts', null, PropertyGenerator::FLAG_PRIVATE);

        // Prepare generators for the hooked methods         $hookMethods = $this->getHookedMethods($reflectionClass);
        $hookMethodGenerators = [];
        foreach ($hookMethods as $method) {
            $hookMethodGenerators[$method->getName()] = $this->createMethodGenerator($method);
        }

        // Add the static 'getHookMethods' method (from Enlight_Hook_Proxy)         $hookMethodNameString = (\count($hookMethodGenerators) > 0) ? ("'" . implode("', '", array_keys($hookMethodGenerators)) . "'") : '';
        $getHookMethodsGenerator = MethodGenerator::fromArray([
            'name' => 'getHookMethods',
            'static' => true,
            'body' => 'return [' . $hookMethodNameString . "];\n",
        ]);
        $getHookMethodsGenerator->setDocBlock('@inheritdoc');
        ClassGeneratorUtils::addMethodIfNotFinal($reflectionClass$classGenerator$getHookMethodsGenerator);

        
Home | Imprint | This part of the site doesn't use cookies.