dev-master
9999999-dev https://github.com/nodrew/NodrewExceptionalBundleSymfony2 Bundle for working with the Exceptional Service
The Requires
by Drew Butler
api exceptional
Symfony2 Bundle for working with the Exceptional Service
For use with the Exceptional service at: http://www.getexceptional.com, (*1)
Ultimately, the NodrewExceptionalBundle files should be downloaded to the
vendor/bundles/Nodrew/Bundle/ExceptionalBundle
directory., (*2)
This can be done in several ways, depending on your preference. The first method is the standard Symfony2 method., (*3)
Using the vendors script, (*4)
Add the following lines in your deps
file:, (*5)
[NodrewExceptionalBundle] git=http://github.com/nodrew/NodrewExceptionalBundle.git target=/bundles/Nodrew/Bundle/ExceptionalBundle
Now, run the vendors script to download the bundle:, (*6)
``` bash $ php bin/vendors install, (*7)
**Using submodules** If you prefer instead to use git submodules, then run the following: ``` bash $ git submodule add http://github.com/nodrew/NodrewExceptionalBundle.git vendor/bundles/Nodrew/Bundle/ExceptionalBundle $ git submodule update --init
``` php registerNamespaces(array( // ... 'Nodrew' => __DIR__.'/../vendor/bundles', )); ``` ### Step 3: Enable the bundle Finally, enable the bundle in the kernel: ``` php securityContext = $securityContext; } /** * {@inheritdoc} */ public function getContext() { $context = array(); $token = $this->securityContext->getToken(); if ($token && $token->isAuthenticated()) { $context['userId'] = $token->getUser()->getId(); $context['username'] = $token->getUser()->getUsername(); } return $context; } } ``` #### Step 2: Create your service id ``` xml // src/Acme/DemoBundle/Resources/config/services.xml , (*8)
<parameters> <parameter key="acme.exceptional.context.handler.class">Acme\DemoBundle\Handler\ExceptionalContextHandler</parameter> </parameters> <services> <service id="acme.exceptional.context.handler" class="%acme.exceptional.context.handler.class%"> <argument type="service" id="security.context" /> </service> </services>
, (*10)
#### Step 3: Add your context id to the config ``` yaml // app/config/config.yml nodrew_exceptional: context_id: acme.exceptional.context.handler
And that's it. Now you should see the username and userId added to the params in exceptional, if a user is logged in. If they are not, then it will be blank. You can of course add your own parameters to that array. Just be sure that it returns an array. If it returns anything else, then it will be skipped., (*11)
Symfony2 Bundle for working with the Exceptional Service
api exceptional