Skip to content

Commit

Permalink
Merge pull request biig-io#27 from swagindustries/feature/melodiiamodel
Browse files Browse the repository at this point in the history
Rename the crud interface for models biig-io#15
  • Loading branch information
Nek- authored Aug 18, 2020
2 parents fff22a6 + f58a2a5 commit 70accae
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Huge BC Break on namespaces. You need to rename all classes used to SwagIndustries instead of Biig
- BC Break on CRUD classes. It's big changes time. So we made the security optional for crud controllers, this has a
- BC Break: on CRUD classes. It's big changes time. So we made the security optional for crud controllers, this has a
consequence on their constructor
- BC Break: `CrudableModelInterface` is now `MelodiiaModel`

## [0.6.0] 2020-06-01
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SwagIndustries\Melodiia\Bridge\Symfony\Form\Listener;

use SwagIndustries\Melodiia\Crud\CrudableModelInterface;
use SwagIndustries\Melodiia\Crud\MelodiiaModel;
use SwagIndustries\Melodiia\Exception\MelodiiaLogicException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
Expand Down Expand Up @@ -34,8 +34,8 @@ public function preSubmit(FormEvent $event)
foreach ($form as $name => $child) {
$lastCollectionIndex = $name;
$item = $child->getData();
if (!$item instanceof CrudableModelInterface) {
throw new MelodiiaLogicException(sprintf('Impossible manage the model of type "%s" inside Melodiia because it does not implement CrudableModelInterface.', get_class($item)));
if (!$item instanceof MelodiiaModel) {
throw new MelodiiaLogicException(sprintf('Impossible manage the model of type "%s" inside Melodiia because it does not implement MelodiiaModel.', get_class($item)));
}
$itemId = (string) $item->getId();
foreach ($data as $inputItem) {
Expand Down
4 changes: 2 additions & 2 deletions src/Crud/Controller/CrudControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace SwagIndustries\Melodiia\Crud\Controller;

use SwagIndustries\Melodiia\Crud\CrudableModelInterface;
use SwagIndustries\Melodiia\Crud\CrudControllerInterface;
use SwagIndustries\Melodiia\Crud\MelodiiaModel;
use SwagIndustries\Melodiia\Exception\MelodiiaLogicException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
Expand All @@ -19,7 +19,7 @@ trait CrudControllerTrait
*/
public function assertModelClassInvalid(string $modelClass): void
{
if (empty($modelClass) || !class_exists($modelClass) || !is_subclass_of($modelClass, CrudableModelInterface::class)) {
if (empty($modelClass) || !class_exists($modelClass) || !is_subclass_of($modelClass, MelodiiaModel::class)) {
throw new MelodiiaLogicException('If you use melodiia CRUD classes, you need to specify a model.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SwagIndustries\Melodiia\Crud;

interface CrudableModelInterface
interface MelodiiaModel
{
/**
* @return string|object that have a __toString() method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SwagIndustries\Melodiia\Test\Bridge\Symfony\Form\Listener;

use SwagIndustries\Melodiia\Bridge\Symfony\Form\Listener\ReorderDataToMatchCollectionListener;
use SwagIndustries\Melodiia\Crud\CrudableModelInterface;
use SwagIndustries\Melodiia\Crud\MelodiiaModel;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Event\PreSubmitEvent;
Expand Down Expand Up @@ -61,7 +61,7 @@ protected function getForm($name = 'name', $data = null)
public function testItReorderDataInputWithFormData()
{
$formData = [
new class() extends \ArrayObject implements CrudableModelInterface {
new class() extends \ArrayObject implements MelodiiaModel {
public function __construct()
{
parent::__construct(['hello' => 'yo', 'world' => 'ye']);
Expand All @@ -75,7 +75,7 @@ public function getId()
return 'foo';
}
},
new class() extends \ArrayObject implements CrudableModelInterface {
new class() extends \ArrayObject implements MelodiiaModel {
public function __construct()
{
parent::__construct(['hello' => 'yoh', 'world' => 'yeh']);
Expand Down Expand Up @@ -109,7 +109,7 @@ public function getId()
public function testItRemovesDataThatDoesNotExistsAnymore()
{
$formData = [
new class() extends \ArrayObject implements CrudableModelInterface {
new class() extends \ArrayObject implements MelodiiaModel {
public function __construct()
{
parent::__construct(['hello' => 'yo', 'world' => 'ye']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Melodiia/TestFixtures/FakeMelodiiaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace SwagIndustries\Melodiia\Test\TestFixtures;

use SwagIndustries\Melodiia\Crud\CrudableModelInterface;
use SwagIndustries\Melodiia\Crud\MelodiiaModel;

class FakeMelodiiaModel implements CrudableModelInterface
class FakeMelodiiaModel implements MelodiiaModel
{
public function getId()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/TestApplication/src/Entity/Todo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace TestApplication\Entity;

use Doctrine\ORM\Mapping as ORM;
use SwagIndustries\Melodiia\Crud\CrudableModelInterface;
use SwagIndustries\Melodiia\Crud\MelodiiaModel;

/**
* @ORM\Entity()
*/
class Todo implements CrudableModelInterface
class Todo implements MelodiiaModel
{
/**
* @ORM\Id
Expand Down

0 comments on commit 70accae

Please sign in to comment.