/**
  * @return \Twig_Function|\Twig_SimpleFunction
  */
 public function getNativeInstance()
 {
     if (Inspect::useClass('\\Twig_Function')->isAbstract()) {
         return new \Twig_SimpleFunction($this->name, $this->callable, $this->options->toArray());
     }
     return new \Twig_Function($this->name, $this->callable, $this->options->toArray());
 }
예제 #2
0
 public function testSetAndGetAndClearFilters()
 {
     $callable = function () {
         return 'test-callable';
     };
     $extension = new TwigExtension();
     $extension->addFilter('test', $callable);
     if (Inspect::useClass('\\Twig_Filter')->isAbstract()) {
         $this->assertInstanceOf('\\Twig_SimpleFilter', $extension->getFilters()[0]);
     } else {
         $this->assertInstanceOf('\\Twig_Filter', $extension->getFilters()[0]);
     }
     $extension->clearFilters();
     $this->assertCount(0, $extension->getFilters());
 }
 public function testBindTo()
 {
     $object = FixtureClassOne::class;
     $method = Inspect::useClass($object, $fixture = new FixtureClassOne());
     $result = $method->visitConstants(function (ConstantInspector $const) use($object) {
         return $this->protectedOne0($const->value()) . '---' . $const->name();
     });
     $this->assertGreaterThan(3, $result);
     foreach ($result as $r) {
         $this->assertNotFalse(strpos($r, 'propProtectedOne0') !== false);
         $this->assertNotFalse(strpos($r, 'ONE_') !== false || strpos($r, 'NULL_') !== false);
     }
 }