Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
legacy-to-ddd : Étape 4. Utilisation du domaine depuis cakephp
- Loading branch information
Showing
4 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Controller\Component; | ||
|
||
use App\Model\Table\BookmarksTable; | ||
use Cake\Controller\Component; | ||
use Cake\Controller\ComponentRegistry; | ||
use Application\GetBookmark\GetBookmarkHandler; | ||
use Cake\ORM\TableRegistry; | ||
use Exception; | ||
|
||
/** | ||
* @property BookmarksTable $Bookmarks | ||
*/ | ||
class ContainerComponent extends Component | ||
{ | ||
private $container = []; | ||
|
||
public function __construct(ComponentRegistry $registry, array $config = []) | ||
{ | ||
parent::__construct($registry, $config); | ||
|
||
$this->Bookmarks = TableRegistry::get('Bookmarks'); | ||
$this->container[GetBookmarkHandler::class] = new GetBookmarkHandler($this->Bookmarks); // On crée nos services ici | ||
} | ||
|
||
public function get($serviceName) | ||
{ | ||
if (!isset($this->container[$serviceName])) { | ||
throw new Exception('Cannot find service'); | ||
} | ||
|
||
return $this->container[$serviceName]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters