Exemplo n.º 1
0
function _main_()
{
    simple_autoloader_register('My', __DIR__, true);
    if (!class_exists('My\\DiDefinition', true)) {
        echo 'COMPILING DEFINITION (and writing to disk at My\\DiDefinition.php)' . PHP_EOL;
        $compiler = new Zend\Di\Definition\Compiler();
        $compiler->addCodeScannerDirectory(new Zend\Code\Scanner\DirectoryScanner(__DIR__ . '/My/'));
        $definition = $compiler->compile();
        $codeGenerator = new Zend\CodeGenerator\Php\PhpFile();
        $codeGenerator->setClass($class = new Zend\CodeGenerator\Php\PhpClass());
        $class->setNamespaceName('My');
        $class->setName('DiDefinition');
        $class->setExtendedClass('\\Zend\\Di\\Definition\\ArrayDefinition');
        $class->setMethod(array('name' => '__construct', 'body' => 'parent::__construct(' . var_export($definition->toArray(), true) . ');'));
        file_put_contents(__DIR__ . '/My/DiDefinition.php', $codeGenerator->generate());
        unset($compiler, $definition, $codeGenerator, $class);
    } else {
        echo 'USING DEFINITION' . PHP_EOL;
    }
    $definition = new My\DiDefinition();
    $di = new Zend\Di\DependencyInjector();
    $di->setDefinition($definition);
    $di->getInstanceManager()->setProperty('My\\DbAdapter', 'username', 'foo');
    $di->getInstanceManager()->setProperty('My\\DbAdapter', 'password', 'bar');
    $c = $di->get('My\\RepositoryA');
    echo $c . PHP_EOL;
}
Exemplo n.º 2
0
    /**
     * getContents()
     *
     * @return string
     */
    public function getContents()
    {
        $codeGenerator = new \Zend\CodeGenerator\Php\PhpFile(array('body' => <<<'EOS'
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(__DIR__ . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application/Application.php';

// Create application, bootstrap, and run
$application = new Zend\Application\Application (
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

EOS
));
        return $codeGenerator->generate();
    }
Exemplo n.º 3
0
 public function getContents()
 {
     $className = $this->getFullClassName($this->_modelName, 'Model');
     $codeGenFile = new \Zend\CodeGenerator\Php\PhpFile(array('fileName' => $this->getPath(), 'classes' => array(new \Zend\CodeGenerator\Php\PhpClass(array('name' => $className)))));
     return $codeGenFile->generate();
 }
Exemplo n.º 4
0
 public function getContents()
 {
     $className = $this->getFullClassName($this->_formName, 'Form');
     $codeGenFile = new \Zend\CodeGenerator\Php\PhpFile(array('fileName' => $this->getPath(), 'classes' => array(new \Zend\CodeGenerator\Php\PhpClass(array('name' => $className, 'extendedClass' => '\\Zend\\Form\\Form', 'methods' => array(new \Zend\CodeGenerator\Php\PhpMethod(array('name' => 'init', 'body' => '/* Form Elements & Other Definitions Here ... */'))))))));
     return $codeGenFile->generate();
 }
Exemplo n.º 5
0
 /**
  * getContents()
  *
  * @return array
  */
 public function getContents()
 {
     $codeGenFile = new \Zend\CodeGenerator\Php\PhpFile(array('classes' => array(new \Zend\CodeGenerator\Php\PhpClass(array('name' => 'Bootstrap', 'extendedClass' => '\\Zend\\Application\\Bootstrap')))));
     return $codeGenFile->generate();
 }
Exemplo n.º 6
0
    /**
     * getContents()
     *
     * @return string
     */
    public function getContents()
    {

        $filter = new \Zend\Filter\Word\DashToCamelCase();

        $className = $filter->filter($this->_projectProviderName) . 'Provider';

        $class = new \Zend\CodeGenerator\Php\PhpClass(array(
            'name' => $className,
            'extendedClass' => '\Zend\Tool\Project\Provider\AbstractProvider'
            ));

        $methods = array();
        foreach ($this->_actionNames as $actionName) {
            $methods[] = new \Zend\CodeGenerator\Php\PhpMethod(array(
                'name' => $actionName,
                'body' => '        /** @todo Implementation */'
                ));
        }

        if ($methods) {
            $class->setMethods($methods);
        }

        $codeGenFile = new \Zend\CodeGenerator\Php\PhpFile(array(
            'classes' => array($class)
            ));

        return $codeGenFile->generate();
    }