OutletProxyGenerator

2 views
Skip to first unread message

Rutkoski

unread,
Dec 9, 2009, 6:34:04 AM12/9/09
to Outlet ORM
Here´s the thing: I'm creating the config dynamically as needed (I
only configure the entities I'm using at the moment), so I call
Outlet::init() and Outlet::createProxies() more than once (don´t know
if that´s the right way to go) and I get an error saying the
*_OutletProxy class already exists.

The same thing would happen if, for example, I created my proxy
classes manually or dumped them to a file (could be usefull).

The fix for the error is very simple. Just added an if inside
OutletProxyGenerator::generate() to check if the class does not
already exists.

function generate() {
...
for ...
if (!class_exists("{$clazz}_OutletProxy")) {
..
}
}
...
}

I think it would be nice to incorporate that into the code.

* Trying out RC1 right now.

Jonathan Ariel

unread,
Dec 9, 2009, 2:04:00 PM12/9/09
to outle...@googlegroups.com
I think you shouldn't call createProxies more than once. Why are you doing that?


--

You received this message because you are subscribed to the Google Groups "Outlet ORM" group.
To post to this group, send email to outle...@googlegroups.com.
To unsubscribe from this group, send email to outlet-orm+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/outlet-orm?hl=en.



Fabio R.

unread,
Dec 9, 2009, 2:17:06 PM12/9/09
to outle...@googlegroups.com
Hi Rodrigo,

Well, the recommended way of generating proxies is to call OutletProxyGenerator::generate() only once.

I've been working on a feature for what will eventually become our 2.0 version that would solve your problem, its what I've called "Proxy autoloading" and basically what it does is it registers itself with spl_autoload and it generates proxies on demand, avoiding the need to call OutletProxyGenerator::generate(), and It also supports caching of proxy classes.

I'll take a look if we can easily adapt the code for 1.0 or if we make it a feature for the next 1.* version.


Thanks for sharing,
--
Fábio Rehm


Rutkoski

unread,
Dec 10, 2009, 7:25:55 AM12/10/09
to Outlet ORM
Well, I'm incoporating Outlet into my framework.
The framework uses autoloading extensively. Including the domain
layer. I don´t load entities all at once.
So, when I need to use an entity, I load that entity, add it to Outlet
´s config and call generate proxies.

On 9 dez, 17:04, Jonathan Ariel <ionat...@gmail.com> wrote:
> I think you shouldn't call createProxies more than once. Why are you doing
> that?
>
> On Wed, Dec 9, 2009 at 9:34 AM, Rutkoski <rutko...@gmail.com> wrote:
> > Here´s the thing: I'm creating the config dynamically as needed (I
> > only configure the entities I'm using at the moment), so I call
> > Outlet::init() and Outlet::createProxies() more than once (don´t know
> > if that´s the right way to go) and I get an error saying the
> > *_OutletProxy class already exists.
>
> > The same thing would happen if, for example, I created my proxy
> > classes manually or dumped them to a file (could be usefull).
>
> > The fix for the error is very simple. Just added an if inside
> > OutletProxyGenerator::generate() to check if the class does not
> > already exists.
>
> > function generate() {
> >  ...
> >  for ...
> >    if (!class_exists("{$clazz}_OutletProxy")) {
> >      ..
> >    }
> >  }
> >  ...
> > }
>
> > I think it would be nice to incorporate that into the code.
>
> > * Trying out RC1 right now.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Outlet ORM" group.
> > To post to this group, send email to outle...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > outlet-orm+...@googlegroups.com<outlet-orm%2Bunsu...@googlegroups.com>
> > .

Fabio R.

unread,
Dec 17, 2009, 5:54:30 PM12/17/09
to outle...@googlegroups.com
Hi all,

I've committed some code to SVN related to this, you can check out at:
  svn://knowledgehead.com/outlet/outlet-orm/branches/proxy-autoload

By default, proxy autoloading and caching is disabled, in order to enable it you have to update your config file by adding the 'proxies' section like this:
array(
  'connection' => array(...), 
  'proxies' => array(
    'autoload' => <boolean>,
    'cache' => <false to disable or path to cache dir>
  ), 
  'classes' => array(...)
)

Basically, when autoload is set to true, outlet will register itself on the __autoload stack using spl_autoload_register and will generate proxies as needed, or (if caching is enabled) it will load the proxy file.

The code is based on released 1.0 RC, so the bug previously reported has not been fixed.
Let us know what you think, this is probably going to be added to 2.0 but I've managed to adapt the code for 1.0

Regards,
--
Fábio Rehm
Reply all
Reply to author
Forward
0 new messages