Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate Proxies manually without CLI in Doctrine?

I'm using Zend Framework to create a web application. Based on several recommendations, I chose Doctrine as my RDBM system.

;---------------------------------------------------
; DOCTRINE CONFIGURATION
;---------------------------------------------------
resources.entityManager.connection.driver = "pdo_mysql"
resources.entityManager.connection.host = "localhost"
resources.entityManager.connection.dbname = "private"
resources.entityManager.connection.user = "private"
resources.entityManager.connection.password = "private"
resources.entityManager.connection.entities = APPLICATION_PATH "/models"
resources.entityManager.connection.proxies.location = APPLICATION_PATH "/models/Proxies"
resources.entityManager.connection.proxies.ns = "Proxies"

; According to Doctrine manual, this should be true for 
; development, and false for production
resources.entityManager.connection.proxies.generate = true

The above is my Doctrine config in the Zend application.ini. Everything is working fine, but I wanted to know in advance how to generate Proxies manually without using the CLI for several reasons. First of all, the Doctrine 2.0 doc mentions that auto-generating Proxies will cause performance issues. Second of all, I still haven't figured out how to use the Doctrine CLI especially that I've moved my project development to a shared server box without command prompt access.

I've been generating Doctrine entities manually by creating the classes. How do I manually generate Doctrine proxies similarly?

like image 639
shiva8 Avatar asked Feb 19 '12 23:02

shiva8


1 Answers

I've found easy way to generate proxies:

    $proxyDir = null; //to genearate to default proxy dir
    $proxyFactory = $em->getProxyFactory();
    $metadatas = $em->getMetadataFactory()->getAllMetadata();
    $proxyFactory->generateProxyClasses($metadatas, $proxyDir);

to generate entities use:

    $classes = $em->getClassMetadataFactory()->getAllMetadata();
    $generator = new \Doctrine\ORM\Tools\EntityGenerator(); 
    $generator->setGenerateAnnotations(true); 
    $generator->setGenerateStubMethods(true); 
    $generator->setRegenerateEntityIfExists(false); 
    $generator->setUpdateEntityIfExists(true); 
    $generator->generate($classes, '/path/to/generate/entities');
like image 198
El' Avatar answered Oct 07 '22 03:10

El'