Skip to content

Commit

Permalink
Merge pull request #498 from ayman-alkom/patch-2
Browse files Browse the repository at this point in the history
doc: fixes
  • Loading branch information
ADmad authored Mar 26, 2017
2 parents b726256 + 40883f2 commit b9b42a7
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/_partials/events/after_bulk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Check Success
public function bulk($id)
{
$this->Crud->on('afterBulk', function(\Cake\Event\Event $event) {
if (!$event->subject()->success) {
if (!$event->getSubject()->success) {
$this->log("Bulk action failed");
}
});
Expand Down
4 changes: 2 additions & 2 deletions docs/_partials/events/after_delete.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Check Success
public function delete($id)
{
$this->Crud->on('afterDelete', function(\Cake\Event\Event $event) {
if (!$event->subject()->success) {
$this->log("Delete failed for entity " . $event->subject()->id);
if (!$event->getSubject()->success) {
$this->log("Delete failed for entity " . $event->getSubject()->id);
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/after_find.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Logging the Found Item
public function delete($id)
{
$this->Crud->on('afterFind', function(\Cake\Event\Event $event) {
$this->log("Found item: " . $event->subject()->entity->id . " in the database");
$this->log("Found item: " . $event->getSubject()->entity->id . " in the database");
});
return $this->Crud->execute();
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/after_lookup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Modify the Result
public function lookup()
{
$this->Crud->on('afterLookup', function(\Cake\Event\Event $event) {
foreach ($event->subject()->entities as $entity) {
foreach ($event->getSubject()->entities as $entity) {
// $entity is an entity
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/after_paginate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Modify the Result
public function index()
{
$this->Crud->on('afterPaginate', function(\Cake\Event\Event $event) {
foreach ($event->subject()->entities as $entity) {
foreach ($event->getSubject()->entities as $entity) {
// $entity is an entity
}
});
Expand Down
8 changes: 4 additions & 4 deletions docs/_partials/events/after_save.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Check Created Status
public function edit($id)
{
$this->Crud->on('afterSave', function(\Cake\Event\Event $event) {
if ($event->subject()->created) {
if ($event->getSubject()->created) {
$this->log("The entity was created");
} else {
$this->log("The entity was updated");
Expand All @@ -40,7 +40,7 @@ Check Success Status
public function edit($id)
{
$this->Crud->on('afterSave', function(\Cake\Event\Event $event) {
if ($event->subject()->success) {
if ($event->getSubject()->success) {
$this->log("The entity was saved successfully");
} else {
$this->log("The entity was NOT saved successfully");
Expand All @@ -58,8 +58,8 @@ Get Entity ID
public function add()
{
$this->Crud->on('afterSave', function(\Cake\Event\Event $event) {
if ($event->subject()->created) {
$this->log("The entity was created with id: " . $event->subject()->id);
if ($event->getSubject()->created) {
$this->log("The entity was created with id: " . $event->getSubject()->id);
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/before_bulk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Stop Bulk Action
{
$this->Crud->on('beforeBulk', function(\Cake\Event\Event $event) {
// Stop the bulk event, the action will not continue
if ($event->subject()->item->author !== 'admin') {
if ($event->getSubject()->item->author !== 'admin') {
$event->stopPropagation();
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/before_delete.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Stop Delete
{
$this->Crud->on('beforeDelete', function(\Cake\Event\Event $event) {
// Stop the delete event, the entity will not be deleted
if ($event->subject()->item->author !== 'admin') {
if ($event->getSubject()->item->author !== 'admin') {
$event->stopPropagation();
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/before_find.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Add Conditions
public function delete($id)
{
$this->Crud->on('beforeFind', function(\Cake\Event\Event $event) {
$event->subject()->query->where(['author' => $this->Auth->user('id')]);
$event->getSubject()->query->where(['author' => $this->Auth->user('id')]);
});
return $this->Crud->execute();
Expand Down
4 changes: 2 additions & 2 deletions docs/_partials/events/set_flash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ If you'd like to configure it on the fly you can use the eventManager to change
.. code-block:: phpinline
$this->eventManager()->on('Crud.setFlash', function (Event $event) {
if ($event->subject()->success) {
$event->subject()->params['class'] = 'alert alert-success alert-dismissible';
if ($event->getSubject()->success) {
$event->getSubject()->params['class'] = 'alert alert-success alert-dismissible';
}
});
6 changes: 3 additions & 3 deletions docs/crud-subject.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ This is an example of the data passed in a ``beforeFind`` event subject.
public function view($id)
{
$this->Crud->on('beforeFind', function (\Cake\Event\Event $event) {
$query = $event->subject()->query;
$primaryKey = $event->subject()->id;
$table = $event->subject()->repository;
$query = $event->getSubject()->query;
$primaryKey = $event->getSubject()->id;
$table = $event->getSubject()->repository;
});
}
Expand Down
2 changes: 1 addition & 1 deletion docs/listeners/api-pagination.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ query object.
public function index()
{
$this->Crud->on('beforePaginate', function (\Cake\Event\Event $event) {
$event->subject()->query->contain([
$event->getSubject()->query->contain([
'Comments' => function ($q) {
return $q
->select(['id', 'name', 'description'])
Expand Down
18 changes: 14 additions & 4 deletions docs/listeners/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ The Api listener overrides the ``Exception.renderer`` for ``api`` requests,
so in case of an error, a standardized error will be returned, in either
``json`` or ``xml`` - according to the API request type.

Create a custom exception renderer by extending the Crud ExceptionRenderer
class and enabling it with the `exceptionRenderer` configuration option.
Create a custom exception renderer by extending the Crud's ``ExceptionRenderer``
class and enabling it with the ``exceptionRenderer`` configuration option.

.. code-block:: php
Expand All @@ -115,9 +115,19 @@ class and enabling it with the `exceptionRenderer` configuration option.
}
}
However if you are using CakePHP 3.3's PSR7 middleware feature the ``exceptionRenderer``
**Note:** However if you are using CakePHP 3.3+'s PSR7 middleware feature the ``exceptionRenderer``
config won't be used and instead you will have to set the ``Error.exceptionRenderer``
config in ``config/app.php`` to ``'Crud\Error\ExceptionRenderer'``.
config in ``config/app.php`` to ``'Crud\Error\ExceptionRenderer'`` as following:

.. code-block:: php
'Error' => [
'errorLevel' => E_ALL,
'exceptionRenderer' => 'Crud\Error\JsonApiExceptionRenderer',
'skipLog' => [],
'log' => true,
'trace' => true,
],
Request type enforcing
----------------------
Expand Down
35 changes: 32 additions & 3 deletions docs/listeners/jsonapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,37 @@ Exception handler
-----------------

The JsonApi listener overrides the ``Exception.renderer`` for ``jsonapi`` requests,
so in case of an error, a standardized error in JSON API format will be returned
for both errors/exceptions and validation errors.
so in case of an error, a standardized error will be returned, in either
``json`` or ``xml`` - according to the API request type.

Create a custom exception renderer by extending the Crud's ``JsonApiExceptionRenderer``
class and enabling it with the ``exceptionRenderer`` configuration option.

.. code-block:: php
<?php
class AppController extends Controller {
public function initialize()
{
parent::initialize();
$this->Crud->config(['listeners.api.exceptionRenderer' => 'App\Error\JsonApiExceptionRenderer']);
}
}
**Note:** However if you are using CakePHP 3.3+'s PSR7 middleware feature the ``exceptionRenderer``
config won't be used and instead you will have to set the ``Error.exceptionRenderer``
config in ``config/app.php`` to ``'Crud\Error\JsonApiExceptionRenderer'`` as following:

.. code-block:: php
'Error' => [
'errorLevel' => E_ALL,
'exceptionRenderer' => 'Crud\Error\JsonApiExceptionRenderer',
'skipLog' => [],
'log' => true,
'trace' => true,
],
Errors/exceptions
^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -387,7 +416,7 @@ and a ``hasMany`` relationship with Cultures:
public function view()
{
$this->Crud->on('beforeFind', function (Event $event) {
$event->subject()->query->contain([
$event->getSubject()->query->contain([
'Currencies',
'Cultures',
]);
Expand Down
6 changes: 3 additions & 3 deletions docs/listeners/related-models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ Example
parent::beforeFilter();
$this->Crud->on('relatedModel', function(\Cake\Event\Event $event) {
if ($event->subject()->association->name() === 'Authors') {
$event->subject()->query->limit(3);
$event->subject()->query->where(['is_active' => true]);
if ($event->getSubject()->association->name() === 'Authors') {
$event->getSubject()->query->limit(3);
$event->getSubject()->query->where(['is_active' => true]);
}
});
Expand Down

0 comments on commit b9b42a7

Please sign in to comment.