Exemplo n.º 1
0
    /**
     * @return string the rendered method. Once eval'ing this method, you must
     * call Method->addToBuiltClass($clazz) on the eval'd class to register the
     * implementation.
     */
    public function render()
    {
        $functionTemplate = <<<EOF
        /**
        * @param *mixed|null
        * @return mixed|null
        */
    <accessLevel> <static> function <methodName>(<typeList>)
    {
        \$fn = self::\$__implementations__["<methodName>"];

        \$joinPoint = new \\Shmock\\ClassBuilder\\DecoratorJoinPoint(<execTarget>,"<methodName>",\$fn);
        \$joinPoint->setArguments(func_get_args());
        \$joinPoint->setDecorators(self::\$__decorators__);

        return \$joinPoint->execute();
    }

EOF;
        $engine = new SprintfEngine("<", ">");
        return $engine->render($functionTemplate, ["accessLevel" => $this->accessLevel, "methodName" => $this->methodName, "typeList" => implode($this->typeList, ","), "static" => $this->isStatic ? "static" : "", "execTarget" => $this->isStatic ? "get_called_class()" : "\$this"]);
    }
Exemplo n.º 2
0
 public function testRenderWithObjectValues()
 {
     $engine = new SprintfEngine();
     $this->assertEquals('foo', $engine->render('{val%s}', array('val' => new ObjectMockForSprintf())));
 }
 /**
  * Render a string
  *
  * @param string $template The template content to render
  * @param array $locals The variable to use in template
  * @return string
  */
 public function render($template, array $locals = array())
 {
     return $this->engine->render($template, $locals);
 }