/** * Generates the parameters code needed to call the constructor with the saved parameters. * * @param string $className Name of the class the method is declared in * @return string The generated paramters code * @author Andreas Förthner <*****@*****.**> */ protected function buildSavedConstructorParametersCode($className) { if ($className === NULL) { return ''; } $parametersCode = ''; $methodParameters = $this->reflectionService->getMethodParameters($className, '__construct'); $methodParametersCount = count($methodParameters); if ($methodParametersCount > 0) { foreach ($methodParameters as $methodParameterName => $methodParameterInfo) { $methodParametersCount--; $parametersCode .= '$this->originalConstructorArguments[\'' . $methodParameterName . '\']' . ($methodParametersCount > 0 ? ', ' : ''); } } return $parametersCode; }
/** * Register method arguments for "render" by analysing the doc comment above. * * @return void * @author Sebastian Kurfürst <*****@*****.**> * @author Bastian Waidelich <*****@*****.**> */ private function registerRenderMethodArguments() { $methodParameters = $this->reflectionService->getMethodParameters(get_class($this), 'render'); if (count($methodParameters) === 0) { return; } if (\F3\Fluid\Fluid::$debugMode) { $methodTags = $this->reflectionService->getMethodTagsValues(get_class($this), 'render'); $paramAnnotations = array(); if (isset($methodTags['param'])) { $paramAnnotations = $methodTags['param']; } } $i = 0; foreach ($methodParameters as $parameterName => $parameterInfo) { $dataType = NULL; if (isset($parameterInfo['type'])) { $dataType = $parameterInfo['type']; } elseif ($parameterInfo['array']) { $dataType = 'array'; } if ($dataType === NULL) { throw new \F3\Fluid\Core\Parser\Exception('could not determine type of argument "' . $parameterName . '" of the render-method in ViewHelper "' . get_class($this) . '". Either the methods docComment is invalid or some PHP optimizer strips off comments.', 1242292003); } $description = ''; if (\F3\Fluid\Fluid::$debugMode && isset($paramAnnotations[$i])) { $explodedAnnotation = explode(' ', $paramAnnotations[$i]); array_shift($explodedAnnotation); array_shift($explodedAnnotation); $description = implode(' ', $explodedAnnotation); } $defaultValue = NULL; if (isset($parameterInfo['defaultValue'])) { $defaultValue = $parameterInfo['defaultValue']; } $this->argumentDefinitions[$parameterName] = new \F3\Fluid\Core\ViewHelper\ArgumentDefinition($parameterName, $dataType, $description, $parameterInfo['optional'] === FALSE, $defaultValue, TRUE); $i++; } }
/** * @test * @author Robert Lemke <*****@*****.**> */ public function getMethodParametersReturnsAnArrayOfParameterNamesAndAdditionalInformation() { $availableClassNames = array('F3\\FLOW3\\Tests\\Reflection\\Fixture\\DummyClassWithMethods'); $reflectionService = new \F3\FLOW3\Reflection\ReflectionService(); $reflectionService->setStatusCache($this->getMock('F3\\FLOW3\\Cache\\Frontend\\StringFrontend', array(), array(), '', FALSE)); $reflectionService->setDataCache($this->getMock('F3\\FLOW3\\Cache\\Frontend\\VariableFrontend', array(), array(), '', FALSE)); $reflectionService->injectSystemLogger($this->getMock('F3\\FLOW3\\Log\\SystemLoggerInterface')); $reflectionService->initialize($availableClassNames); $expectedParameters = array('arg1' => array('position' => 0, 'byReference' => FALSE, 'array' => FALSE, 'optional' => FALSE, 'class' => NULL, 'allowsNull' => TRUE, 'type' => 'string'), 'arg2' => array('position' => 1, 'byReference' => TRUE, 'array' => FALSE, 'optional' => FALSE, 'class' => NULL, 'allowsNull' => TRUE), 'arg3' => array('position' => 2, 'byReference' => FALSE, 'array' => FALSE, 'optional' => FALSE, 'class' => 'stdClass', 'allowsNull' => FALSE, 'type' => 'stdClass'), 'arg4' => array('position' => 3, 'byReference' => FALSE, 'array' => FALSE, 'optional' => TRUE, 'class' => NULL, 'allowsNull' => TRUE, 'defaultValue' => 'default')); $actualParameters = $reflectionService->getMethodParameters('F3\\FLOW3\\Tests\\Reflection\\Fixture\\DummyClassWithMethods', 'firstMethod'); $this->assertEquals($expectedParameters, $actualParameters); }