Extending Doctrine entities using Zend_* an My_* library

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Extending Doctrine entities using Zend_* an My_* library

tridem
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

Marco Pivetta
a) what kind of autoloader are you using? Did you register all namespaces?
I'm currently using the standard Zend_Loader_Autoloader from ZF 1.X and it
works fine with Doctrine2 (no need for Doctrine Common autoloader).
b) As I see you're trying to load stuff like "\Zend\Date();". ZF 1.X doesn't
use php 5.3's namespaces, so you would just go for "\Zend_Date();" instead.
c) If (b) wasn't the problem could you please show some of the exceptions
thrown?
d) "use \My\Entity\Base as My_Entity_Base;" - Is this a wanted behaviour?
Marco Pivetta
@Ocramius <http://twitter.com/Ocramius>
http://marco-pivetta.com



On 18 April 2011 09:58, tridem-zend <[hidden email]> wrote:

> I am switching from Zend_Db (including mappers and DbTable) to Doctrine
> 2.0.
> My former directory strucure was:
>
> /application/
> /application/models/
> /application/models/DbTable
> /application/models/mappers
>
> So far so good I created my models from database including all relations. I
> still have a copy of my old models and simply added the Doctrine entities
> here:
>
> /application/
> /application/Entities/
> /application/Entities/Proxies
> /application/Entities/Repositiories
> /application/models/
> /application/models/DbTable
> /application/models/mappers
>
> My old models extended an abstract class with methods like "toArray" or
> "toDojoArray" etc. and I would like to continue using them. That's why I
> tried to extend my Entity f.e.:
>
>
> <?php
>
> namespace Entities;
>
> #use \Zend\Date as Zend_Date;
> use \My\Entity\Base as My_Entity_Base;
>
> /**
>  * History
>  *
>  * @Table(name="history")
>  * @Entity(repositoryClass="\Entities\Repositories\HistoryRepository")
>  */
> class History extends My_Entity_Base
>
>
> First of all is this a good idea? Unfortunately though my autoloading seems
> to work fine I still have problems with using namespaces. Could someone
> show
> me the correct path to extend?
>
> My second problem is using Zend_* inside the entites f.e.:
>
>    public function toDojoArray()
>    {
>        $creationDate  = (!null == $this->getInsertDatetime()) ? new
> \Zend\Date($this->getInsertDatetime()) : new \Zend\Date();
>
>        $data = array(
>            'id'             => $this->getId(),
>            'name'           => $this->getHistoryName(),
>            'creationDate'  => array(
>                "_type"  => "Date",
>                "_value" => $creationDate->get(Zend_Date::ISO_8601)
>            ),
>            'creationDate'   => $this->getCreationDate()
>        );
>
>        return $data;
>    }
>
>
> The Doctrine entity simply doesn't load the Zend library.
>
> Please help! Thanks!
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Extending-Doctrine-entities-using-Zend-an-My-library-tp3456839p3456839.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

tridem
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

Marco Pivetta
If you're using the standard Zend_Application stack (and it's autoloader) I
suggest you to drop the Doctrine autoloader and keep Zend's default... Much
less confusing :)
Check this Gist, it's the (not really clean) resource I use to startup a
Doctrine2 EntityManager:
https://gist.github.com/925033
The only thing you need to do to avoid using D2's autoloader is taking care
(like I did from lines 67 to 77 in the gist) of Entity Proxies :)

Marco Pivetta
@Ocramius <http://twitter.com/Ocramius>
http://marco-pivetta.com



On 18 April 2011 10:51, tridem-zend <[hidden email]> wrote:

> Thanks Marco, now I understand namespaces a little bit more and my
> "toDojoArray" method works now.
> Since the getInsertDatetime returns a Doctrine DateTime object I had to
> format it. The \Zend_Date works fine now too.
>
>
>    public function toDojoArray()
>    {
>        $creationDate  = (!null == $this->getInsertDatetime()) ? new
> \Zend_Date($this->getInsertDatetime()->format('Y-m-d H:i:s') : new
> \Zend_Date();
>
>        $data = array(
>            'id'             => $this->getId(),
>            'name'           => $this->getHistoryName(),
>            'creationDate'  => array(
>                "_type"  => "Date",
>                "_value" => $creationDate->get(Zend_Date::ISO_8601)
>            ),
>            'creationDate'   => $this->getCreationDate()
>        );
>
>        return $data;
>    }
>
>
> I added the My_ (/library/My/) namespace to the Doctrine autoloader in my
> Bootstrap.php
>
>
> public function _initDoctrine() {
>        $classLoader = new \Doctrine\Common\ClassLoader('MY',
> APPLICATION_PATH . '/../library');
>        $classLoader->register();
> }
>
>
> and tried to extend the entity by using
>
> class History extends My_Entity_Base.
>
> Is this the right way?
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Extending-Doctrine-entities-using-Zend-an-My-library-tp3456839p3456947.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

tridem
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

weierophinney
Administrator
-- tridem-zend <[hidden email]> wrote
(on Monday, 18 April 2011, 04:07 AM -0700):
> You were right, removing the loaders made it less confusing.
> I finally managed to extend my abstract class. I accidentally used
> namespaces there too though ZF does not support them.

Correction: ZF 1.X simply doesn't *use* namespaces. However, you can
still use them within code using ZF 1.X. You'll need to provide your own
autoloaders for handling namespaced code, however (you can grab the
StandardAutoloader from ZF2 if you want to handle both namespaces and
ZF1's vendor prefix style).

> I will now copy my business logic from my earlier models to the
> entities and then rename 'Entities' to 'Application_Model'. If I am
> lucky my application should continue to work smoothly and hopefully
> faster!

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

A.J. Brown
Hey Matthew,

The Zend Framework Autoloader appears to support namespaces for the
most part.  I'm using them just fine in my projects.  The only
exception I've discovered so far is bootstrap resources, which must
follow the old PEAR style "namespacing" (vendor prefixing).  The
documentation claims that it works as of ZF 1.10 as well:

http://framework.zend.com/manual/en/zend.loader.autoloader.html



On Mon, Apr 18, 2011 at 10:09 AM, Matthew Weier O'Phinney
<[hidden email]> wrote:

> -- tridem-zend <[hidden email]> wrote
> (on Monday, 18 April 2011, 04:07 AM -0700):
>> You were right, removing the loaders made it less confusing.
>> I finally managed to extend my abstract class. I accidentally used
>> namespaces there too though ZF does not support them.
>
> Correction: ZF 1.X simply doesn't *use* namespaces. However, you can
> still use them within code using ZF 1.X. You'll need to provide your own
> autoloaders for handling namespaced code, however (you can grab the
> StandardAutoloader from ZF2 if you want to handle both namespaces and
> ZF1's vendor prefix style).
>
>> I will now copy my business logic from my earlier models to the
>> entities and then rename 'Entities' to 'Application_Model'. If I am
>> lucky my application should continue to work smoothly and hopefully
>> faster!
>
> --
> Matthew Weier O'Phinney
> Project Lead            | [hidden email]
> Zend Framework          | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>



--
A.J. Brown
Software Engineering Fanatic
blog : http://ajbrown.org
talk  : (937) 540-0099
chat : IntypicaAJ
tweet: @adrianjbrown

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

Marco Pivetta
Yep, that's the same for me as I use XML config, and that's a trouble if I
want to use some resources from My\Personal\Library  like
<My\Personal\Library\Super\Resource/> (obviously won't work) :\
It's not an issue of the autoloader anyway, it's about resources
bootstrapping and loading...
Marco Pivetta
@Ocramius <http://twitter.com/Ocramius>
http://marco-pivetta.com



On 18 April 2011 17:28, A.J. Brown <[hidden email]> wrote:

> Hey Matthew,
>
> The Zend Framework Autoloader appears to support namespaces for the
> most part.  I'm using them just fine in my projects.  The only
> exception I've discovered so far is bootstrap resources, which must
> follow the old PEAR style "namespacing" (vendor prefixing).  The
> documentation claims that it works as of ZF 1.10 as well:
>
> http://framework.zend.com/manual/en/zend.loader.autoloader.html
>
>
>
> On Mon, Apr 18, 2011 at 10:09 AM, Matthew Weier O'Phinney
> <[hidden email]> wrote:
> > -- tridem-zend <[hidden email]> wrote
> > (on Monday, 18 April 2011, 04:07 AM -0700):
> >> You were right, removing the loaders made it less confusing.
> >> I finally managed to extend my abstract class. I accidentally used
> >> namespaces there too though ZF does not support them.
> >
> > Correction: ZF 1.X simply doesn't *use* namespaces. However, you can
> > still use them within code using ZF 1.X. You'll need to provide your own
> > autoloaders for handling namespaced code, however (you can grab the
> > StandardAutoloader from ZF2 if you want to handle both namespaces and
> > ZF1's vendor prefix style).
> >
> >> I will now copy my business logic from my earlier models to the
> >> entities and then rename 'Entities' to 'Application_Model'. If I am
> >> lucky my application should continue to work smoothly and hopefully
> >> faster!
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead            | [hidden email]
> > Zend Framework          | http://framework.zend.com/
> > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
> >
> > --
> > List: [hidden email]
> > Info: http://framework.zend.com/archives
> > Unsubscribe: [hidden email]
> >
> >
> >
>
>
>
> --
> A.J. Brown
> Software Engineering Fanatic
> blog : http://ajbrown.org
> talk  : (937) 540-0099
> chat : IntypicaAJ
> tweet: @adrianjbrown
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Extending Doctrine entities using Zend_* an My_* library

Wil Moore III
In reply to this post by A.J. Brown
A.J. Brown wrote
The only exception I've discovered so far is bootstrap resources, which must follow the old PEAR style "namespacing" (vendor prefixing).  The documentation claims that it works as of ZF 1.10 as well:
http://framework.zend.com/manual/en/zend.loader.autoloader.html
Hey A.J.,

I agree that the ZF 1.x autoloader works fine, and I used that for months without issue before switching to the Symfony Universal Class Loader (for reasons of granularity).

If you want true namespaces in your application resources you can use the following configuration recipe (assumes you are using .ini)

pluginPaths.your\application\resource\  = SOURCE_PATH "/library/your/application/resource"

Where "your\application\resource\" is the namespace prefix to your application resources. In other words, you'd define your resources as depicted below:

NOTE: you need the trailing "\" in the pluginPaths definition.

<?php
namespace your\application\resource;
class Assets extends AbstractResource {}


--
Wil Moore III

Best Practices for Working with Open-Source Developers
http://www.faqs.org/docs/artu/ch19s02.html

Why is Bottom-posting better than Top-posting:
http://www.caliburn.nl/topposting.html

DO NOT TOP-POST and DO trim your replies:
http://linux.sgms-centre.com/misc/netiquette.php#toppost