zf2 use zf1 registry

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

zf2 use zf1 registry

Norbert Máté
Hi everyone,
  I have an old application that was written using zf 1.9. I have to
develop new features and I thought it's time to move on and develop the new
features as zf2 modules.
  The problem is that it uses registry for storing the set up dependency
injection instance. I wan't to reuse the data access layer of the old app
and to be able to do this I setup the DI and save it in the old Registry:
\Zend_Registry::set('di',$di);

I do this in the Module.php.
The problem is that if I want to get the DI instance in the other parts of
the project like in a controller with \Zend_Registry::get('di'); what I get
back does not remembers the DI settings. It's like it is overwritten but I
have put a breakpoint in the Zend_Registry::set function and it is called a
single time.

Probably I will change the registry to Service manager but I can't find out
the Registry why does not work.

Do you have any idea?

Thanks,
Norbert.
Reply | Threaded
Open this post in threaded view
|

Re: zf2 use zf1 registry

Marco Pivetta
Heya!

Mind sharing the module code or generally making a gist with a simple
example? It's hard to follow what is going on :)

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 4 July 2013 19:51, Norbert Máté <[hidden email]> wrote:

> Hi everyone,
>   I have an old application that was written using zf 1.9. I have to
> develop new features and I thought it's time to move on and develop the new
> features as zf2 modules.
>   The problem is that it uses registry for storing the set up dependency
> injection instance. I wan't to reuse the data access layer of the old app
> and to be able to do this I setup the DI and save it in the old Registry:
> \Zend_Registry::set('di',$di);
>
> I do this in the Module.php.
> The problem is that if I want to get the DI instance in the other parts of
> the project like in a controller with \Zend_Registry::get('di'); what I get
> back does not remembers the DI settings. It's like it is overwritten but I
> have put a breakpoint in the Zend_Registry::set function and it is called a
> single time.
>
> Probably I will change the registry to Service manager but I can't find out
> the Registry why does not work.
>
> Do you have any idea?
>
> Thanks,
> Norbert.
>
Reply | Threaded
Open this post in threaded view
|

Re: zf2 use zf1 registry

samsonasik
This post has NOT been accepted by the mailing list yet.
In reply to this post by Norbert Máté
try to set variable of controller via SharedEventManager like the following pseudocode :

public function onBootstrap($e)
{
   $registry = \Zend_Registry::set('di', 'value');
    $sharedEventManager  = $e->getApplication()->getEventManager()->getSharedManager();
    $sharedEventManager->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($ev) use($registry) {
             $controller = $ev->getTarget();
             $controller->variable = $registry->get('di');
     });
}
Reply | Threaded
Open this post in threaded view
|

Re: zf2 use zf1 registry

Norbert Máté
In reply to this post by Marco Pivetta
Hi Marco,
thanks for you reply.
I have tried to make a sample application where I can show you what is the
problem but in the sample app was no problem. So probably I did something
wrong but I have changed since than and I am using service manager instead
of registry.

Thanks,
Norbert.


On 4 July 2013 21:32, Marco Pivetta <[hidden email]> wrote:

> Heya!
>
> Mind sharing the module code or generally making a gist with a simple
> example? It's hard to follow what is going on :)
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>
>
> On 4 July 2013 19:51, Norbert Máté <[hidden email]> wrote:
>
>> Hi everyone,
>>   I have an old application that was written using zf 1.9. I have to
>> develop new features and I thought it's time to move on and develop the
>> new
>> features as zf2 modules.
>>   The problem is that it uses registry for storing the set up dependency
>> injection instance. I wan't to reuse the data access layer of the old app
>> and to be able to do this I setup the DI and save it in the old Registry:
>> \Zend_Registry::set('di',$di);
>>
>> I do this in the Module.php.
>> The problem is that if I want to get the DI instance in the other parts of
>> the project like in a controller with \Zend_Registry::get('di'); what I
>> get
>> back does not remembers the DI settings. It's like it is overwritten but I
>> have put a breakpoint in the Zend_Registry::set function and it is called
>> a
>> single time.
>>
>> Probably I will change the registry to Service manager but I can't find
>> out
>> the Registry why does not work.
>>
>> Do you have any idea?
>>
>> Thanks,
>> Norbert.
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Database, Table and Column Naming Conventions for ZF2 modules

wingman
Hello guys,

Is there Database, Table and Column Naming Conventions for ZF2 modules?
As a proof of a concept we try to build a simple system using only the available
ZF2 modules from <http://modules.zendframework.com/> .
This is my composer.json:

{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"minimum-stability": "alpha",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": ">2.2.0rc1",
"doctrine/doctrine-orm-module": "0.7.*",
"zf-commons/zfc-user": "0.1.*",
"zf-commons/zfc-user-doctrine-orm": "0.1.*",
"bjyoungblood/bjy-authorize": "1.2.*",
"manuakasam/sam-user": "dev-master",
"cdli/CdliTwoStageSignup": "dev-master"
}
}

We are planning to add a CMS as well:

- <http://www.ejoom.com/libra-zend-framework-2-cms>

- <http://got-cms.com/>

What we try to achieve is to build a simple system like one build with
WordPress. I should be able to log in as administrator and manage posts.

But different modules use different table names for the same Entities.

ZfcUser -> table name "user" - singular

BjyAuthorize -> for the same table "users" - plural

For the names of the fields we have similar problem.

At one point the modules will not be compatible.

I think we will need some kind of  Database, Table and Column Naming Conventions
for ZF2 modules.

Is this the appropriate place to raise this question?



Best Regards

Stoyan Cheresharov


Free your mind! You can fly!
Reply | Threaded
Open this post in threaded view
|

Re: Database, Table and Column Naming Conventions for ZF2 modules

Marco Pivetta
Heya!

Just to make it clear, BjyAuthorize doesn't provide any standard table
names by default... All configs are opt-in.

Yes, modules may become incompatible if they are not configurable, but
that's up to the developers to sort out.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 11 July 2013 18:15, [hidden email]
<[hidden email]>wrote:

> Hello guys,
>
> Is there Database, Table and Column Naming Conventions for ZF2 modules?
> As a proof of a concept we try to build a simple system using only the
> available
> ZF2 modules from <http://modules.zendframework.com/> .
> This is my composer.json:
>
> {
> "name": "zendframework/skeleton-application",
> "description": "Skeleton Application for ZF2",
> "license": "BSD-3-Clause",
> "keywords": [
> "framework",
> "zf2"
> ],
> "homepage": "http://framework.zend.com/",
> "minimum-stability": "alpha",
> "require": {
> "php": ">=5.3.3",
> "zendframework/zendframework": ">2.2.0rc1",
> "doctrine/doctrine-orm-module": "0.7.*",
> "zf-commons/zfc-user": "0.1.*",
> "zf-commons/zfc-user-doctrine-orm": "0.1.*",
> "bjyoungblood/bjy-authorize": "1.2.*",
> "manuakasam/sam-user": "dev-master",
> "cdli/CdliTwoStageSignup": "dev-master"
> }
> }
>
> We are planning to add a CMS as well:
>
> - <http://www.ejoom.com/libra-zend-framework-2-cms>
>
> - <http://got-cms.com/>
>
> What we try to achieve is to build a simple system like one build with
> WordPress. I should be able to log in as administrator and manage posts.
>
> But different modules use different table names for the same Entities.
>
> ZfcUser -> table name "user" - singular
>
> BjyAuthorize -> for the same table "users" - plural
>
> For the names of the fields we have similar problem.
>
> At one point the modules will not be compatible.
>
> I think we will need some kind of  Database, Table and Column Naming
> Conventions
> for ZF2 modules.
>
> Is this the appropriate place to raise this question?
>
>
>
> Best Regards
>
> Stoyan Cheresharov
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Database, Table and Column Naming Conventions for ZF2 modules

wingman
Hello Marco,

BjyAuthorize provides entities "User.php.dist" and  "Role.php.dist" in the
folder "vendor\bjyoungblood\bjy-authorize\data".

They don't simply extend
"vendor\zf-commons\zfc-user\src\ZfcUser\Entity\User.php" as you do in
"vendor\zf-commons\zfc-user-doctrine-orm\src\ZfcUserDoctrineORM\Entity\User.php".
They use a new class.

The Entity "vendor\bjyoungblood\bjy-authorize\data\User.php.dist" has a code
snippet:
...

/**
* An example of how to implement a role aware user entity.
*
* @ORM\Entity
* @ORM\Table(name="users") <-------------------- NOTICE - plural
*
* @author Tom Oram <[hidden email]>
*/
class User implements UserInterface, ProviderInterface

...

If we use "User.php" entity from "BjyAuthorize" and run
 "vendor\bin\doctrine.bat orm:schema-tool:create",

We end up having a table called "users" - plural.

If you follow "ZfcUser" installation you will have a table "user" - singular.

In the module "SamUser < https://github.com/manuakasam/SamUser > " and the famous
tutorial "ZfcUser, BjyAuthorize and Doctrine working together
< http://samminds.com/2013/03/zfcuser-bjyauthorize-and-doctrine-working-together/ >
" Sam is using the mentioned above "User.php.dist" from "BjyAuthorize".

So we end up having 3 tables:

* role - singular
* users - plural
* users_roles
We are not consistent!
I know the Doctrine idea "Simply said: Forget about the database!" :) I love it!
But in the case of modules we can not completely forget the database.
Some people may not use Doctrine in the modules.
If we want to build a repository of reusable compatible modules we need   Database, Table and Column Naming Conventions.


 Best Regards,

Stoyan Cheresharov
 
 
Marco Pivetta <[hidden email]> hat am 12. Juli 2013 um 00:08 geschrieben:

Heya!

Just to make it clear, BjyAuthorize doesn't provide any standard table names by default... All configs are opt-in.

Yes, modules may become incompatible if they are not configurable, but that's up to the developers to sort out.



On 11 July 2013 18:15, [hidden email] <[hidden email]> wrote:
Hello guys,

Is there Database, Table and Column Naming Conventions for ZF2 modules?
As a proof of a concept we try to build a simple system using only the available
ZF2 modules from < http://modules.zendframework.com/> .
This is my composer.json:

{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": " http://framework.zend.com/",
"minimum-stability": "alpha",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": ">2.2.0rc1",
"doctrine/doctrine-orm-module": "0.7.*",
"zf-commons/zfc-user": "0.1.*",
"zf-commons/zfc-user-doctrine-orm": "0.1.*",
"bjyoungblood/bjy-authorize": "1.2.*",
"manuakasam/sam-user": "dev-master",
"cdli/CdliTwoStageSignup": "dev-master"
}
}

We are planning to add a CMS as well:

- < http://www.ejoom.com/libra-zend-framework-2-cms>

- < http://got-cms.com/>

What we try to achieve is to build a simple system like one build with
WordPress. I should be able to log in as administrator and manage posts.

But different modules use different table names for the same Entities.

ZfcUser -> table name "user" - singular

BjyAuthorize -> for the same table "users" - plural

For the names of the fields we have similar problem.

At one point the modules will not be compatible.

I think we will need some kind of  Database, Table and Column Naming Conventions
for ZF2 modules.

Is this the appropriate place to raise this question?



Best Regards

Stoyan Cheresharov


 


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]
Free your mind! You can fly!