Exemplo n.º 1
0
<?php

namespace MovieApp {
    use Zend\Di\Definition\Annotation as Di;
    class Lister
    {
        public $finder;
        /**
         * @Di\Inject()
         */
        public function setFinder(Finder $finder)
        {
            $this->finder = $finder;
        }
    }
    class Finder
    {
    }
}
namespace {
    // bootstrap
    include 'zf2bootstrap' . (stream_resolve_include_path('zf2bootstrap.php') ? '.php' : '.dist.php');
    $di = new Zend\Di\Di();
    $di->definitions()->getDefinitionForClass('MovieApp\\Lister')->getIntrospectionStrategy()->setUseAnnotations(true);
    $lister = $di->get('MovieApp\\Lister');
    // expression to test
    $works = $lister->finder instanceof MovieApp\Finder;
    // display result
    echo ($works ? 'It works!' : 'It DOES NOT work!') . PHP_EOL;
}
<?php

namespace Foo\Bar {
    use Zend\Di\Definition\Annotation as Di;
    class Baz
    {
        public $bam;
        /**
         * @Di\Inject()
         */
        public function injectBam(Bam $bam)
        {
            $this->bam = $bam;
        }
    }
    class Bam
    {
    }
}
namespace {
    include 'zf2bootstrap.php';
    $di = new Zend\Di\Di();
    $di->definitions()->getDefinitionForClass('Foo\\Bar\\Baz')->getIntrospectionStrategy()->setUseAnnotations(true);
    $baz = $di->get('Foo\\Bar\\Baz');
    // expression to test
    $works = $baz->bam instanceof Foo\Bar\Bam;
    // display result
    echo $works ? 'It works!' : 'It DOES NOT work!';
}