Re: [fw-general] Modules, the EventManager, and the SharedEventManager

2013-05-12 Thread David Muir

On 10/05/13 23:11, Michael Gooden wrote:

Hi David,

It should not be firing twice, however you are trying to use the 
shared event manager the wrong way.


If you want to have a listener fire for EVERY dispatch ever, then just 
attach to normal event manager on EVENT_DISPATCH in one place. If you 
attach it in the MyModule it will still fire when you access a 
controller in the Application module. Is that what you need?


It was more as an experiment to see what would happen. I was more 
confused by different tutorials showing listeners being attached to the 
EventManager and the SharedEventManager without explaining why one 
should be used over the other.


As for firing twice, I agree, that shouldn't be happening, but 
Zend\Mvc\Application.php triggers MvcEvent::EVENT_DISPATCH on line 309 
and Zend\Mvc\Controller\AbstractController triggers it on line 115.
In my opinion this is a bug, and those should be two separate events, 
but there's probably not much that can be done about it now without 
breaking BC.


Cheers,
David



Cheers,

Michael


On 10 May 2013 15:01, David Muir > wrote:


Michael,

Thanks for the explanation. It does explain the issue I have having.

So the gist is:


$sharedEvents->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH



means that this even will only be triggered if the context is that
namespace. So the one in Application will fire if the context is
"Application" and the one in MyModule will fire if the context is
"MyModule".

So as an experiment, in Application I tried attaching a listener
to 'MyModule' instead of __NAMESPACE__ and it work as expected. It
only fires when hitting a controller in MyModule.

But what if I want to attach something that is triggered in all
contexts on the dispatch event? I tried using the * wildcard, but
now the shared listeners get hit twice:

shared event listener from application module called
shared event listener from my module called
event listener from application module called
event listener from my module called
shared event listener from application module called
shared event listener from my module called

If my understanding is correct, this happens because there are two
EventManager involved. First is the Application's EventManager,
which first triggers the shared events, then triggers the local
events. Then the controller itself triggers
MvcEvent::EVENT_DISPATCH on its own EventManager instance when the
controller's dispatch() method gets called. This in turn triggers
the shared events a 2nd time.

I guess I got exactly what I asked for, but wasn't
expecting MvcEvent::EVENT_DISPATCH to be triggered twice. Kind of
feels wrong...

Cheers,
David

On 10/05/2013, at 4:46 PM, Michael Gooden
mailto:mich...@bluepointweb.com>> wrote:


Hi David,

Keep in mind that you are working with the Zend\Mvc\Application's
EventManager instance. Try and follow the code execution in the
Application::run() function, to see when and why different events
fire.

I would hazard a guess and say that you are accessing a
controller in the MyModule, and not in the main Application
module. If you run a controller from the Application module, you
will then see the 'shared event from application' message show
instead of from mymodule. The reason this is happening is because
the shared event manager listener you are attaching is listening
for the event identifier of __NAMESPACE__. When the dispatch
event gets called against a controller under MyModule, only the
listener tied to the namespace of that controller will be fired.
The reason you will always see both normal event listener
messages is because those listeners are both attached to the
dispatch event.

I feel I am failing at explaining this, can you add me on Skype?

Cheers,

Michael Gooden


On 10 May 2013 03:41, David Muir mailto:davidkm...@gmail.com>> wrote:

I'm getting some weird behaviour with the EventManager and
SharedEventManager when used in the Application module vs
other modules.

Application Module:

public function onBootstrap(MvcEvent $e)
{
//$e->getApplication()->getServiceManager()->get('translator');
$eventManager=
$e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);

$eventManager->attach(MvcEvent::EVENT_DISPATCH, function
($event){
echo 'event listener from application module
called' . PHP_EOL;
});

$sharedEvents = $eventManager->getSharedManager();

$sharedEvents->attach(__NAMESPACE__,
MvcEvent::EVENT_DISPATCH, function ($event){
echo 's

Re: [fw-general] Zend 2 - entity/model/mapper/service front end back end best practice

2013-05-12 Thread Marco Pivetta
Heya!

Modules are _NOT_ separate containers of controllers! They share services,
so re-use them!

You can just define what you want to have in your container and then re-use
it in admin and frontend controllers. No need to rewrite the logic twice :)

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 11 May 2013 15:14, whisher  wrote:

> Hi all,
> I'd like to know what's the best practice to manage
> entity/model/mapper/service in
> for instance Blog Admin modules.
> I should set up different entity/model/mapper/service
> or share all the stuff from within my Admin module ?
> Thanks in advance.
>
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Zend-2-entity-model-mapper-service-front-end-back-end-best-practice-tp4659998.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>


[fw-general] Re: zend 2 pagination control route default action

2013-05-12 Thread whisher
thx just a lot for the point :)



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/zend-2-pagination-control-route-default-action-tp4660004p4660007.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] ZfcRbac and identity getting issue

2013-05-12 Thread Mohammad ZeinEddin
Hello,
can any one please help answering this question?
http://stackoverflow.com/questions/16497449/zfcrbac-can-not-get-identity-from-an-mvc-event

I have a ZF2 application that uses ZfcRbac, and it is integrated with an
old existing application, and so I need to get the authentication from the
other application, and I do get the identity from the old system by a
function as the following:

$em->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, array($this,
'checkAuthentication'), 100);

and in ZfcRbac configuration I changed the identity provider and I get and
identity for ZfcRbac as the following:

'service_manager' => array(
'factories' => array(
'standard_identity' => function ($sm) {
$someIdentity = $sm->get('SomeAuthService')->getIdentity();
$roles = $someIdentity->getRoles();
$identity = new \ZfcRbac\Identity\StandardIdentity($roles);
return $identity;
},
)
)

but the problem is that the first time I request the page I can not get the
identity from the authentication service since the 'standard_identity' will
execute the code in the "onBootStrap" and it will find the session storage
empty and so I will always get 'unauthorized' access. I want the standard
identity to execute somehow after the event route because then I will have
the identity saved. any one can help with that?
Best Regards,


Re: [fw-general] zend 2 pagination control route default action

2013-05-12 Thread Marco Pivetta
The routing configuration is invalid:

'/user[/:action][/id/:id][/page/:page]',

How is this supposed to work? What's the order of the optional parts? :)

You probably want to have:

'/user[/:action[/id/:id[/page/:page]]]',

instead


Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 12 May 2013 17:26, whisher  wrote:

> Hi,
> module.config.php
> router' => array(
> 'routes' => array(
> 'btitadmin_route' => array(
> 'type' => 'literal',
> 'options' => array(
> 'route'=> '/admin',
> 'defaults' => array(
> 'controller' =>
> 'BtitAdmin\Controller\AdminController',
> 'action' => 'index',
> ),
> ),
> 'may_terminate' => true,
> 'child_routes' => array(
> 'user' => array(
> 'type' => 'segment',
> 'options' => array(
> 'route' =>
> '/user[/:action][/id/:id][/page/:page]',
> 'constraints' => array(
> 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
> 'id' => '[0-9]+',
> 'page' => '[0-9]+',
> ),
> 'defaults' => array(
> 'controller' =>
> 'BtitAdmin\Controller\UserController',
> 'action' => 'index',
> 'id'=>0,
> 'page'=>1
> ),
> ),
> ),
>
> BtitAdmin/view/btit-admin/user/index.phtml
> echo $this->paginationControl(
> $paginator, 'Sliding', '/partial/paginator',array('route'
> =>'btitadmin_route/user')
> );
> BtitAdmin/view/btit-admin/partial/paginator.phtml
> echo $this->url($this->route, array('page' => $page));
>
> the problem is when I click on the link I got
> admin/user/page/2
> instead of
> admin/user/index/page/2
>
> Can you help me,please ?
>
> Thanks in advance.
>
>
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/zend-2-pagination-control-route-default-action-tp4660004.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>


[fw-general] zend 2 pagination control route default action

2013-05-12 Thread whisher
Hi,
module.config.php
router' => array(
'routes' => array(
'btitadmin_route' => array(
'type' => 'literal',
'options' => array(
'route'=> '/admin',
'defaults' => array(
'controller' =>
'BtitAdmin\Controller\AdminController',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'user' => array(
'type' => 'segment',
'options' => array(
'route' =>
'/user[/:action][/id/:id][/page/:page]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'page' => '[0-9]+',
),
'defaults' => array(
'controller' =>
'BtitAdmin\Controller\UserController',
'action' => 'index',
'id'=>0,
'page'=>1
),
),
),

BtitAdmin/view/btit-admin/user/index.phtml
echo $this->paginationControl(
$paginator, 'Sliding', '/partial/paginator',array('route'
=>'btitadmin_route/user')
);
BtitAdmin/view/btit-admin/partial/paginator.phtml
echo $this->url($this->route, array('page' => $page));

the problem is when I click on the link I got
admin/user/page/2
instead of
admin/user/index/page/2

Can you help me,please ?

Thanks in advance.





--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/zend-2-pagination-control-route-default-action-tp4660004.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Re: zf2 - one/many-to-many relationships

2013-05-12 Thread Marco Pivetta
@Jeremiah he is asking specifically for a Zend\Db solution...

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 12 May 2013 07:50, Jeremiah Small  wrote:

> I like Doctrine 2 module.
>
> Jeremiah
>
> On May 11, 2013, at 7:04 PM, tonystamp  wrote:
>
> > Anyone got any pointers on the best way to achieve the above? Not many
> > tutorials out there on the subject for zf2.
> >
> >
> >
> > --
> > View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/zf2-one-many-to-many-relationships-tp4659910p465.html
> > Sent from the Zend Framework mailing list archive at Nabble.com.
> >
> > --
> > List: fw-general@lists.zend.com
> > Info: http://framework.zend.com/archives
> > Unsubscribe: fw-general-unsubscr...@lists.zend.com
> >
> >
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>


[fw-general] various ZendService/Twitter problems due to recent API change

2013-05-12 Thread phmarty
For those of you who might be able to help out, but don't feel like reading
the whole post: i'm looking for a working example - including OAuth
authentication - that can fetch me twitter user-timelines using the new v1.1
API from twitter and using ZendService/Twitter. Furthermore, i want to use 
application-only-authentication
   (so it is not
necessary for users to to interact)

--

For those of you interested in what i've tried so far, read on.

I'm running into multiple problems trying something so easy as getting a
feed of public tweets from various twitter-accounts.
>From what i understood on the twitter website i had to use 
application-only-authentication
  

I've configured composer.json as follows to include zendservice/twitter:

/"zendframework/zendservice-twitter": "dev-master" /

this, in turn, also includes zendoauth:/ "zendframework/zendoauth":
">=2.0.0"/

(just so you know which versions i'm using)


The first problem really is all the outdated documenation that is still
online. But well i won't get into that now.

So, reading the docs i understand i must first authenticate using ZendOAuth
(the documenation says this is not necessary for public timelines, but it's
one of those things that is not correct in the documenation - _all_ api
calls must be authenticated)

After reading the getting-started document (which was not sufficient) and
various other pages on the internet i was able to able to piece this
together:

$config = array(
"consumerKey"   => "[mykey]",
"consumerSecret"=> "[mysecret]",
"requestTokenUrl"   => "http://api.twitter.com/oauth2/token";
);
$consumer = new \ZendOAuth\Consumer($config);
try {
$token = $consumer->getRequestToken();
var_dump($token);
} catch (\Exception $e) {
echo "Error getting token: ".$e->getMessage()."\n";
}

This still doesn't work however; the main reason being that twitter
*requires* a body that says:

*grant_type=client_credentials*

So, i created a few of my own classes extending on the existing ones, that
allowed me to set a body. I'm using Curl as the adapter for the http-client
and i don't know if it's because of that, but existing methods like
setContent didn't have any effect on the body. This is what it now looks
like:

$adapter = new \MyOwn\Http\Client\Adapter\TwitterCurl();
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);

$config = array(
"consumerKey"   => "[mykey]",
"consumerSecret"=> "[mysecret]",
"requestTokenUrl"   => "https://api.twitter.com/oauth2/token";
);

$consumer = new \MyOwn\OAuth\Consumer($config);
$client = $consumer->getHttpClient();
$client->setAdapter($adapter);
$consumer->setHttpClient($client);
try {
$token = $consumer->getRequestToken();
var_dump($token);
} catch (\Exception $e) {
echo "Error getting token: ".$e->getMessage()."\n";
}

And finally, after lots of reading and debugging i got a response with a
bearer-token!

But, i'm still stuck, actually interfacing with twitter. When i create a
zendserver/twitter object, passing in my token, it keeps saying it's not
valid. I've found a hundred different examples of how to pass in the
variables, with no clear idea of which one is the right one. This is, among
other things, what i've tried:

$twitter = new \ZendService\Twitter\Twitter(array(
'accessToken' => $token,
'oauth_options' => array(
'username' => $username,
),
));
$adapter = new \Zend\Http\Client\Adapter\Curl();
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
$twitter->getHttpClient()->setAdapter($adapter);
$response = $twitter->account->verifyCredentials();
The $token being the variable from the previous code-snippet

This gains me a 400 - Bad Request though
When i capture the outoing request i can see that this is sent:

GET /1.1/account/verify_credentials.json HTTP/1.1
Host: api.twitter.com
Connection: close
Accept-Encoding: gzip, deflate
User-Agent: Zend\Http\Client

It doesn't communicate the token at all!

I really hope there is someone here who can shed some light on things. I've
been going at this for three days now, reading loads of (outdated)
documenation and hacking my way around this.
I starting to get the feeling it would've been far easier to build this
myself from scratch :(



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/various-ZendService-Twitter-problems-due-to-recent-API-change-tp4660002.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://