Skip to content

Commit

Permalink
minor #455 Misc. minor fixes (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

Misc. minor fixes

Commits
-------

739d7fc Misc. minor fixes
  • Loading branch information
javiereguiluz committed Sep 15, 2015
2 parents d4acc3b + 739d7fc commit 0bff199
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
33 changes: 22 additions & 11 deletions Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ protected function editAction()
}

$id = $this->request->query->get('id');
if (!$entity = $this->em->getRepository($this->entity['class'])->find($id)) {
throw new EntityNotFoundException(array('action' => 'edit', 'entity' => $this->entity, 'entity_id' => $id));
}
$entity = $this->findCurrentEntity();

$fields = $this->entity['edit']['fields'];

Expand Down Expand Up @@ -229,9 +227,7 @@ protected function showAction()
$this->dispatch(EasyAdminEvents::PRE_SHOW);

$id = $this->request->query->get('id');
if (!$entity = $this->em->getRepository($this->entity['class'])->find($id)) {
throw new EntityNotFoundException(array('action' => 'show', 'entity' => $this->entity, 'entity_id' => $id));
}
$entity = $this->findCurrentEntity();

$fields = $this->entity['show']['fields'];
$deleteForm = $this->createDeleteForm($this->entity['name'], $id);
Expand Down Expand Up @@ -287,8 +283,6 @@ protected function newAction()

$this->dispatch(EasyAdminEvents::POST_PERSIST, array('entity' => $entity));

$refererUrl = $this->request->query->get('referer', '');

return $this->redirect($this->generateUrl('admin', array('action' => 'list', 'entity' => $this->entity['name'])));
}

Expand Down Expand Up @@ -324,9 +318,7 @@ protected function deleteAction()
$form->handleRequest($this->request);

if ($form->isValid()) {
if (!$entity = $this->em->getRepository($this->entity['class'])->find($id)) {
throw new EntityNotFoundException(array('action' => 'delete', 'entity' => $this->entity, 'entity_id' => $id));
}
$entity = $this->findCurrentEntity();

$this->dispatch(EasyAdminEvents::PRE_REMOVE, array('entity' => $entity));

Expand Down Expand Up @@ -731,4 +723,23 @@ private function isPostgreSqlUsedByEntity($entityClass)

return $em->getConnection()->getDatabasePlatform() instanceof PostgreSqlPlatform;
}

/**
* Looks for the objet that corresponds to the selected 'id' of the current
* entity. No parameters are required because all the information is stored
* globally in the class.
*
* @return object The entity
*
* @throws EntityNotFoundException
*/
private function findCurrentEntity()
{
$id = $this->request->query->get('id');
if (!$entity = $this->em->getRepository($this->entity['class'])->find($id)) {
throw new EntityNotFoundException(array('entity' => $this->entity, 'entity_id' => $id));
}

return $entity;
}
}
12 changes: 6 additions & 6 deletions Tests/Reflection/fixtures/FooBarClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class FooBarClass
// CamelCase - Methods with the same name as properties
public $publicPropertyWithSameNameMethod;
public function publicPropertyWithSameNameMethod() {
return $publicPropertyWithSameNameMethod;
return $this->publicPropertyWithSameNameMethod;
}

protected $protectedPropertyWithSameNameMethod;
public function protectedPropertyWithSameNameMethod() {
return $protectedPropertyWithSameNameMethod;
return $this->protectedPropertyWithSameNameMethod;
}

private $privatePropertyWithSameNameMethod;
public function privatePropertyWithSameNameMethod() {
return $privatePropertyWithSameNameMethod;
return $this->privatePropertyWithSameNameMethod;
}

// CamelCase - Getters but no setters
Expand Down Expand Up @@ -149,17 +149,17 @@ public function isPrivatePropertyWithIsserWithoutHasserWithoutGetterWithoutSette
// snake_case - Methods with the same name as properties
public $snake_case_public_property_with_same_name_method;
public function snake_case_public_property_with_same_name_method() {
return $snake_case_public_property_with_same_name_method;
return $this->snake_case_public_property_with_same_name_method;
}

protected $snake_case_protected_property_with_same_name_method;
public function snake_case_protected_property_with_same_name_method() {
return $snake_case_protected_property_with_same_name_method;
return $this->snake_case_protected_property_with_same_name_method;
}

private $snake_case_private_property_with_same_name_method;
public function snake_case_private_property_with_same_name_method() {
return $snake_case_private_property_with_same_name_method;
return $this->snake_case_private_property_with_same_name_method;
}

// snake_case - Getters but no setters
Expand Down

0 comments on commit 0bff199

Please sign in to comment.