<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Tue May 21 08:09:11 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-717/DDC-717.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-717] Do not use files when using proxy autogeneration</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-717</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;Proxy classes are generated in less than 1ms for me. I prefer to not have a &quot;build&quot; step to reducing loading time by a milisecond, so I use autogenerate.&lt;/p&gt;

&lt;p&gt;For users like me, wouldn&apos;t it be nicer if we wouldn&apos;t even have to configure a proxy dir and those files were never written (since they&apos;re not read more than once anyway)?&lt;/p&gt;</description>
                <environment></environment>
            <key id="11676">DDC-717</key>
            <summary>Do not use files when using proxy autogeneration</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="jakajancar">Jaka Jancar</reporter>
                        <labels>
                    </labels>
                <created>Thu, 22 Jul 2010 17:52:55 +0000</created>
                <updated>Mon, 4 Jul 2011 21:47:47 +0000</updated>
                                                    <fixVersion>2.x</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>2</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="13668" author="jakajancar" created="Thu, 22 Jul 2010 18:32:00 +0000"  >&lt;p&gt;This very minimal patch removes the use of these temporary files:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;--- library/Doctrine/ORM/Proxy/ProxyFactory.php	(revision 2)
+++ library/Doctrine/ORM/Proxy/ProxyFactory.php	(working copy)
@@ -78,9 +78,8 @@
         $fqn = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_proxyNamespace . &apos;\\&apos; . $proxyClassName;
 
         &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_autoGenerate &amp;amp;&amp;amp; ! class_exists($fqn, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)) {
-            $fileName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . &apos;.php&apos;;
-            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateProxyClass($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;getClassMetadata($className), $proxyClassName, $fileName, self::$_proxyClassTemplate);
-            require $fileName;
+            $file = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateProxyClass($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;getClassMetadata($className), $proxyClassName, &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, self::$_proxyClassTemplate);
+            eval(&apos;?&amp;gt;&apos;.$file);
         }
 
         &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;getMetadataFactory()-&amp;gt;hasMetadataFor($fqn)) {
@@ -144,6 +143,9 @@
 
         $file = str_replace($placeholders, $replacements, $file);
 
+        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($fileName === &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
+            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $file;
+
         file_put_contents($fileName, $file);
     }
 
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="13671" author="beberlei" created="Fri, 23 Jul 2010 03:14:30 +0000"  >&lt;p&gt;The proxy dir is used for the &quot;doctrine orm:generate-proxies&quot; command in the case of &quot;autogenerate= false&quot;, so you need to define it anyways.&lt;/p&gt;

&lt;p&gt;You have to use proxies, the option is not for Proxy yes/no. If you have autogenerate=false and doctrine requires a proxy for a use case but can&apos;t find it you will get a fatal error.&lt;/p&gt;</comment>
                    <comment id="13672" author="beberlei" created="Fri, 23 Jul 2010 03:15:54 +0000"  >&lt;p&gt;I just saw the eval() keyword, ieeks &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/wink.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; It could maybe be a convenience option for those that don&apos;t want to use proxy direcotiries, however i am not sure.&lt;/p&gt;</comment>
                    <comment id="13675" author="jakajancar" created="Fri, 23 Jul 2010 03:22:32 +0000"  >&lt;p&gt;eval() is no different than writing code to a file and using require().&lt;/p&gt;

&lt;p&gt;When using runtime-generated proxies, there are no benefits (that I know of) from writing them to a file. The disadvantages are:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;slower because of write disk access&lt;/li&gt;
	&lt;li&gt;has problems with high concurrency, unless special care is taken (&lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-716&quot; title=&quot;Proxy autogeneration fails with concurrent requests&quot;&gt;&lt;del&gt;DDC-716&lt;/del&gt;&lt;/a&gt;)&lt;/li&gt;
	&lt;li&gt;potentially has permission problems if code is executed by different users (e.g. nobody for a daemon and www-data for http)&lt;/li&gt;
	&lt;li&gt;requires setup of a writable directory&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This is a nicer patch, which makes _generateProxyClass() return a string, just like other _generate* methods:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;--- library/Doctrine/ORM/Proxy/ProxyFactory.php	(revision 2)
+++ library/Doctrine/ORM/Proxy/ProxyFactory.php	(working copy)
@@ -78,9 +78,8 @@
         $fqn = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_proxyNamespace . &apos;\\&apos; . $proxyClassName;
 
         &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_autoGenerate &amp;amp;&amp;amp; ! class_exists($fqn, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)) {
-            $fileName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . &apos;.php&apos;;
-            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateProxyClass($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;getClassMetadata($className), $proxyClassName, $fileName, self::$_proxyClassTemplate);
-            require $fileName;
+            $code = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateProxyClass($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;getClassMetadata($className), $proxyClassName);
+            eval($code);
         }
 
         &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;getMetadataFactory()-&amp;gt;hasMetadataFor($fqn)) {
@@ -107,19 +106,19 @@
         foreach ($classes as $class) {
             $proxyClassName = str_replace(&apos;\\&apos;, &apos;&apos;, $class-&amp;gt;name) . &apos;Proxy&apos;;
             $proxyFileName = $proxyDir . $proxyClassName . &apos;.php&apos;;
-            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateProxyClass($class, $proxyClassName, $proxyFileName, self::$_proxyClassTemplate);
+            $code = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateProxyClass($class, $proxyClassName);
+            file_put_contents($proxyFileName, &lt;span class=&quot;code-quote&quot;&gt;&quot;&amp;lt;?php\n&quot;&lt;/span&gt; . $code);
         }
     }
 
     /**
      * Generates a proxy class file.
      *
-     * @param $class
-     * @param $originalClassName
+     * @param ClassMetadata $class
      * @param $proxyClassName
-     * @param $file The path of the file to write to.
+     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string The code of the generated methods.
      */
-    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; function _generateProxyClass($class, $proxyClassName, $fileName, $file)
+    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; function _generateProxyClass(ClassMetadata $class, $proxyClassName)
     {
         $methods = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateMethods($class);
         $sleepImpl = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateSleep($class);
@@ -142,9 +141,9 @@
             $methods, $sleepImpl
         );
 
-        $file = str_replace($placeholders, $replacements, $file);
+        $file = str_replace($placeholders, $replacements, self::$_proxyClassTemplate);
 
-        file_put_contents($fileName, $file);
+        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $file;
     }
 
     /**
@@ -244,8 +243,7 @@
 
     /** Proxy class code template */
     &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; $_proxyClassTemplate =
-&apos;&amp;lt;?php
-
+&apos;
 namespace &amp;lt;namespace&amp;gt;;
 
 /**
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="13679" author="beberlei" created="Sat, 24 Jul 2010 06:21:53 +0000"  >&lt;p&gt;Scheduled usage of eval() for 2.1, if the following conditions exist:&lt;/p&gt;

&lt;p&gt;1. Autogenerate is set to TRUE&lt;br/&gt;
2. No Proxy Directory is configured.&lt;/p&gt;</comment>
                    <comment id="13681" author="jakajancar" created="Sat, 24 Jul 2010 06:26:14 +0000"  >&lt;p&gt;Great, this is even better. This way you can have 1) autogenerated in ram-only, 2) autogenerated in files and 3) pregenerated.&lt;/p&gt;

&lt;p&gt;And the minimal amount of config needed to get up and running is reduced, which is always nice.&lt;/p&gt;</comment>
                    <comment id="13682" author="beberlei" created="Sat, 24 Jul 2010 06:34:49 +0000"  >&lt;p&gt;you should know though, eval is dead slow. It generates the necessary proxies on EACH request and that cannot be cached in APC.&lt;/p&gt;</comment>
                    <comment id="13684" author="jakajancar" created="Sat, 24 Jul 2010 06:46:26 +0000"  >&lt;p&gt;It&apos;s no slower than current autogeneration (file_put_contents+require). TBH, I don&apos;t know why anyone would want to use that over eval(), but I don&apos;t mind it being there.&lt;/p&gt;

&lt;p&gt;Pre-generation is, of course, a different thing. Seems like a valid tradeoff to offer: build/a bit of config/better perfomance vs. no build/no config/potentially slower.&lt;/p&gt;</comment>
                    <comment id="13685" author="beberlei" created="Sat, 24 Jul 2010 07:52:39 +0000"  >&lt;p&gt;Yes, that is because file_put_contents + require is a development only strategy. The manual clearly states that autogenerate has to be false in production.&lt;/p&gt;</comment>
                    <comment id="13933" author="romanb" created="Thu, 12 Aug 2010 09:39:12 +0000"  >&lt;p&gt;Using eval() instead of producing and requiring the file in the case of enabled auto-generation of proxy classes sounds like a good improvement for 2.1 to make proxies more transparent during deveopment and for anyone for whom performance is no issue.&lt;/p&gt;

&lt;p&gt;I&apos;m increasing the priority as I think it is easy to implement for 2.1 and a good enhancement.&lt;/p&gt;</comment>
                    <comment id="15243" author="k-fish" created="Wed, 9 Feb 2011 04:09:51 +0000"  >&lt;p&gt;A note on why having the proxies written to a file can be useful even with autogenerate being on: it makes it really easy to check the proxy code being generated. I use that a lot currently.&lt;/p&gt;

&lt;p&gt;The solution suggested, giving three possibilities is cool, though.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>