Skip to content

Commit

Permalink
Ajoute un auto-discover du modèle dans les contrôleurs
Browse files Browse the repository at this point in the history
  • Loading branch information
Donov4n committed Jan 5, 2021
1 parent 44ea71b commit 4aafe8f
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 92 deletions.
8 changes: 0 additions & 8 deletions server/src/App/Controllers/AttributeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@

namespace Robert2\API\Controllers;

use Robert2\API\Models\Attribute;

class AttributeController extends BaseController
{
public function __construct($container)
{
parent::__construct($container);

$this->model = new Attribute();
}
}
8 changes: 8 additions & 0 deletions server/src/App/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ abstract class BaseController

public function __construct($container)
{
if ($this->model === null) {
$modelName = preg_replace('/Controller$/', '', class_basename($this));
$modelFullName = sprintf('\\Robert2\\API\\Models\\%s', $modelName);
if (class_exists($modelFullName, true)) {
$this->model = new $modelFullName();
}
}

$this->container = $container;
$this->itemsCount = $container->settings['maxItemsPerPage'];
}
Expand Down
8 changes: 0 additions & 8 deletions server/src/App/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@

namespace Robert2\API\Controllers;

use Robert2\API\Models\Category;

class CategoryController extends BaseController
{
public function __construct($container)
{
parent::__construct($container);

$this->model = new Category();
}
}
8 changes: 0 additions & 8 deletions server/src/App/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@
use Slim\Http\Response;

use Robert2\API\Errors;
use Robert2\API\Models\Company;
use Robert2\API\Controllers\Traits\Taggable;

class CompanyController extends BaseController
{
use Taggable;

public function __construct($container)
{
parent::__construct($container);

$this->model = new Company;
}

// ——————————————————————————————————————————————————————
// —
// — Model dedicated methods
Expand Down
9 changes: 0 additions & 9 deletions server/src/App/Controllers/CountryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
use Slim\Http\Request;
use Slim\Http\Response;

use Robert2\API\Models\Country;

class CountryController extends BaseController
{
public function __construct($container)
{
parent::__construct($container);

$this->model = new Country();
}

public function getAll(Request $request, Response $response): Response
{
$data = $this->model
Expand Down
9 changes: 0 additions & 9 deletions server/src/App/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@
namespace Robert2\API\Controllers;

use Robert2\API\Errors;
use Robert2\API\Models\Event;
use Robert2\API\Controllers\Traits\WithPdf;
use Robert2\API\Models\Material;
use Slim\Http\Request;
use Slim\Http\Response;

class EventController extends BaseController
{
use WithPdf;

public function __construct($container)
{
parent::__construct($container);

$this->model = new Event();
}

// ——————————————————————————————————————————————————————
// —
// — Getters
Expand Down
8 changes: 0 additions & 8 deletions server/src/App/Controllers/MaterialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Robert2\API\Controllers;

use Robert2\API\Errors;
use Robert2\API\Models\Material;
use Robert2\API\Models\Attribute;
use Robert2\API\Models\Event;
use Robert2\API\Controllers\Traits\Taggable;
Expand All @@ -15,13 +14,6 @@ class MaterialController extends BaseController
{
use Taggable;

public function __construct($container)
{
parent::__construct($container);

$this->model = new Material();
}

// ——————————————————————————————————————————————————————
// —
// — Getters
Expand Down
9 changes: 0 additions & 9 deletions server/src/App/Controllers/ParkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@
namespace Robert2\API\Controllers;

use Robert2\API\Errors;
use Robert2\API\Models\Material;
use Robert2\API\Models\Park;
use Slim\Http\Request;
use Slim\Http\Response;

class ParkController extends BaseController
{
public function __construct($container)
{
parent::__construct($container);

$this->model = new Park();
}

// ——————————————————————————————————————————————————————
// —
// — Model dedicated methods
Expand Down
8 changes: 0 additions & 8 deletions server/src/App/Controllers/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@

namespace Robert2\API\Controllers;

use Robert2\API\Models\Person;
use Robert2\API\Controllers\Traits\Taggable;

class PersonController extends BaseController
{
use Taggable;

public function __construct($container)
{
parent::__construct($container);

$this->model = new Person();
}
}
8 changes: 0 additions & 8 deletions server/src/App/Controllers/SubCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@

namespace Robert2\API\Controllers;

use Robert2\API\Models\SubCategory;

class SubCategoryController extends BaseController
{
public function __construct($container)
{
parent::__construct($container);

$this->model = new SubCategory();
}
}
9 changes: 0 additions & 9 deletions server/src/App/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@
namespace Robert2\API\Controllers;

use Robert2\API\Errors;
use Robert2\API\Models\Material;
use Robert2\API\Models\Tag;
use Slim\Http\Request;
use Slim\Http\Response;

class TagController extends BaseController
{
public function __construct($container)
{
parent::__construct($container);

$this->model = new Tag();
}

public function getPersons(Request $request, Response $response): Response
{
$id = (int)$request->getAttribute('id');
Expand Down
8 changes: 0 additions & 8 deletions server/src/App/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
use Slim\Http\Response;

use Robert2\API\Errors;
use Robert2\API\Models\User;
use Robert2\API\Config\Config;

class UserController extends BaseController
{
public function __construct($container)
{
parent::__construct($container);

$this->model = new User;
}

// ——————————————————————————————————————————————————————
// —
// — Model dedicated methods
Expand Down

0 comments on commit 4aafe8f

Please sign in to comment.