/** * @see Behat\Behat\Context\Loader\ContextLoaderInterface::load() */ public function load(ContextInterface $context) { $reflection = new \ReflectionObject($context); foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodRefl) { foreach ($this->readMethodAnnotations($reflection->getName(), $methodRefl) as $annotation) { if ($annotation instanceof DefinitionInterface) { $this->definitionDispatcher->addDefinition($annotation); } elseif ($annotation instanceof TransformationInterface) { $this->definitionDispatcher->addTransformation($annotation); } elseif ($annotation instanceof HookInterface) { $this->hookDispatcher->addHook($annotation); } } } }
public function load(ContextInterface $context) { foreach ($this->sitemap->findClasses() as $className) { $reflection = new \ReflectionClass($className); if ($reflection->isSubclassOf('Behat\\Behat\\Context\\BehatContext')) { continue; } foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodRefl) { if ($methodRefl->getDeclaringClass() != $reflection) { continue; } // only own methods; intentionally != because reflection is not identical foreach ($this->readMethodAnnotations($reflection->getName(), $methodRefl) as $annotation) { if ($annotation instanceof \Behat\Behat\Definition\DefinitionInterface) { $this->definitionDispatcher->addDefinition($annotation); } elseif ($annotation instanceof \Behat\Behat\Definition\TransformationInterface) { $this->definitionDispatcher->addTransformation($annotation); } elseif ($annotation instanceof \Behat\Behat\Hook\HookInterface) { $this->hookDispatcher->addHook($annotation); } } } } }
/** * Defines argument transformation. * * @param string $regex transformation regex (to find specific argument) * @param Callback $callback transformation callback (must return transformed argument) */ public function Transform($regex, $callback) { $this->dispatcher->addTransformation(new Transformation($callback, $regex)); }