Upgrade to Pro — share decks privately, control downloads, hide ads and more …

思想と理想の果てに / At the end of thought and ideal

nrs
December 01, 2019

思想と理想の果てに / At the end of thought and ideal

at PHP Conference Japan 2019
各種 URL: https://nrslib.com/phpcon-2019-proposal/

# URL
HomePage: https://nrslib.com
Twitter: https://twitter.com/nrslib

nrs

December 01, 2019
Tweet

More Decks by nrs

Other Decks in Programming

Transcript

  1. 2

  2. 3

  3. 4

  4. 5

  5. 6

  6. 7

  7. 10

  8. 12

  9. 16

  10. 20

  11. 78

  12. 79

  13. 82

  14. 85

  15. 91

  16. 111 Controller Presenter Use Case Interactor Use Case Input Port

    Use Case Output Port < I > < I > もっと細かく
  17. 119

  18. 120

  19. 121

  20. 122 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } }
  21. 123 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } アプリケーションが 要求するデータに 入力を変換
  22. 124 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } アプリケーションが 要求するデータに 入力を変換
  23. 125

  24. 126

  25. 128 DS : Data Structure class UserCreateInputData { private $name;

    private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } }
  26. 129

  27. 130

  28. 132

  29. 133

  30. 134 class UserCreateInteractor implements UserCreateInputPortInterface { private $repository; private $outputPort;

    public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); } ... }
  31. 135 class UserCreateInteractor implements UserCreateInputPortInterface { private $repository; private $outputPort;

    public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); } ... }
  32. 136 class UserCreateInteractor implements UserCreateInputPortInterface { private $repository; private $outputPort;

    public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); } ... }
  33. 137 class UserCreateInteractor implements UserCreateInputPortInterface { private $repository; private $outputPort;

    public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); } ... }
  34. 138

  35. 139

  36. 143

  37. 144

  38. 145 class UserRepository implements UserRepositoryInterface { public function save(User $user)

    { DB::table('users') ->updateOrInsert( ['id' => $user->getId()], ['name' => $user->getName()] ); } public function find(UserId $id) { $user = DB::table('users')->where('id', $id->getValue())->first(); return new User($id, $user->name); } ... } オブジェクトの 永続化・再構築が できればなんでもいい
  39. 146

  40. 147

  41. 148 class User { private $id; private $name private $role;

    public function __construct( UserId $id, UserName $name, UserRole $role ) { if (is_null($id)) throw new ¥Exception(); if (is_null($name)) throw new ¥Exception(); if (is_null($role)) throw new ¥Exception(); $this->id = $id; $this->name = $name; $this->role = $role; } ... public function changeName(UserName $name) { if (is_null($name)) throw new ¥Exception(); $this->name = $name; } }
  42. 149 class User { private $id; private $name private $role;

    public function __construct( UserId $id, UserName $name, UserRole $role ) { if (is_null($id)) throw new ¥Exception(); if (is_null($name)) throw new ¥Exception(); if (is_null($role)) throw new ¥Exception(); $this->id = $id; $this->name = $name; $this->role = $role; } ... public function changeName(UserName $name) { if (is_null($name)) throw new ¥Exception(); $this->name = $name; } } class UserName { private $value; public function __construct(string $value) { if (is_null($value)) throw new ¥Exception(); if (strlen($value) < 3) throw new ¥Exception(); if (strlen($value) > 10) throw new ¥Exception(); $this->value = $value; } public function getValue(): string { return $this->value; } }
  43. 150 class User { private $id; private $name private $role;

    public function __construct( UserId $id, UserName $name, UserRole $role ) { if (is_null($id)) throw new ¥Exception(); if (is_null($name)) throw new ¥Exception(); if (is_null($role)) throw new ¥Exception(); $this->id = $id; $this->name = $name; $this->role = $role; } ... public function changeName(UserName $name) { if (is_null($name)) throw new ¥Exception(); $this->name = $name; } } class UserName { private $value; public function __construct(string $value) { if (is_null($value)) throw new ¥Exception(); if (strlen($value) < 3) throw new ¥Exception(); if (strlen($value) > 10) throw new ¥Exception(); $this->value = $value; } public function getValue(): string { return $this->value; } } データモデルとは異なる
  44. 151

  45. 152

  46. 153 class UserCreateOutputData { private $createdId; public function __construct(string $createdId)

    { $this->createdId = $createdId; } public function getCreatedId(): string { return $this->createdId; } }
  47. 154

  48. 155

  49. 157

  50. 158

  51. 159 class UserCreatePresenter implements UserCreateOutputPortInterface { private $middleware; public function

    __construct(ClarcMiddleware $middleware) { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputData) { $viewModel = new UserCreateViewModel($outputData); $this->middleware->setData(view('user.create', compact('viewModel'))); } }
  52. 160

  53. 161

  54. 162 class UserCreateViewModel { private $createdId; public function __construct(UserCreateOutputData $source)

    { $this->createdId = $source->getCreatedId(); } public function getCreatedId(): string { return $this->createdId; } }
  55. 163 class UserCreateViewModel { private $createdId; public function __construct(UserCreateOutputData $source)

    { $this->createdId = $source->getCreatedId(); } public function getCreatedId(): string { return $this->createdId; } } <h1>Test</h1> <p> {{$viewModel->getCreatedId()}} </p>
  56. 165

  57. 166 Flow of Control class UserController { private $inputPort; public

    function __construct(UserCreateInputPortInterface $inputPort) { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string {
  58. 167 Flow of Control Create class UserController { private $inputPort;

    public function __construct(UserCreateInputPortInterface $inputPort) { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string {
  59. 168 Flow of Control Call class UserController { private $inputPort;

    public function __construct(UserCreateInputPortInterface $inputPort) { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string {
  60. 173 Flow of Control class UserCreateInteractor implements UserCreateInputPortInterface { private

    $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); }
  61. 174 Flow of Control Create class UserCreateInteractor implements UserCreateInputPortInterface {

    private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); }
  62. 175 Flow of Control Call class UserCreateInteractor implements UserCreateInputPortInterface {

    private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); }
  63. 176 Flow of Control interface UserRepositoryInterface { function find(UserId $id):

    User; function save(User $user); function delete(User $user); }
  64. 177 Flow of Control Delegate interface UserRepositoryInterface { function find(UserId

    $id): User; function save(User $user); function delete(User $user); }
  65. 178 Flow of Control class UserRepository implements UserRepositoryInterface { ...

    public function save(User $user) { DB::table('users') ->updateOrInsert( ['id' => $user->getId()], ['name' => $user->getName()] ); } public function find(UserId $id) { $user = DB::table('users')->where('id', $id->getValue())->first(); return new User($id, $user->name); } }
  66. 179 Flow of Control Access class UserRepository implements UserRepositoryInterface {

    ... public function save(User $user) { DB::table('users') ->updateOrInsert( ['id' => $user->getId()], ['name' => $user->getName()] ); } public function find(UserId $id) { $user = DB::table('users')->where('id', $id->getValue())->first(); return new User($id, $user->name); } }
  67. 180 Flow of Control class UserCreateInteractor implements UserCreateInputPortInterface { ...

    public function handle(UserCreateInputData $input { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); }
  68. 181 Flow of Control Create class UserCreateInteractor implements UserCreateInputPortInterface {

    ... public function handle(UserCreateInputData $input { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); }
  69. 182 Flow of Control Call class UserCreateInteractor implements UserCreateInputPortInterface {

    ... public function handle(UserCreateInputData $input { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); $this->repository->save($user); $outputdata = new UserCreateOutputData($id); $this->outputPort->output($outputdata); }
  70. 188 188 Business Logic Database Access Module Data Access Interface

    Change Involve Involve leading 主導権をビジネスロジックに
  71. 196 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } }
  72. 197 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } }
  73. 198 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } } interface UserCreateInputPortInterface { function handle(UserCreateInputData $inputData); }
  74. 199 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } } interface UserCreateInputPortInterface { function handle(UserCreateInputData $inputData); } class UserCreateInteractor implements UserCreateInputPortInterfac { private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) );
  75. 200 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } } interface UserCreateInputPortInterface { function handle(UserCreateInputData $inputData); } class UserCreateInteractor implements UserCreateInputPortInterfac { private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); interface UserCreateOutputPortInterface { function output(UserCreateOutputData $outputData); }
  76. 201 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } } interface UserCreateInputPortInterface { function handle(UserCreateInputData $inputData); } class UserCreateInteractor implements UserCreateInputPortInterfac { private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); interface UserCreateOutputPortInterface { function output(UserCreateOutputData $outputData); } class UserCreateOutputData { private $createdId; public function __construct(string $createdId) { $this->createdId = $createdId; } public function getCreatedId(): string { return $this->createdId; } }
  77. 202 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } } interface UserCreateInputPortInterface { function handle(UserCreateInputData $inputData); } class UserCreateInteractor implements UserCreateInputPortInterfac { private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); interface UserCreateOutputPortInterface { function output(UserCreateOutputData $outputData); } class UserCreateOutputData { private $createdId; public function __construct(string $createdId) { $this->createdId = $createdId; } public function getCreatedId(): string { return $this->createdId; } } class UserCreatePresenter implements UserCreateOutputPor { private $middleware; public function __construct(ClarcMiddleware $middlew { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputD { $viewModel = new UserCreateViewModel($outputData $this->middleware->setData(view('view_resource', } }
  78. 203 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } } interface UserCreateInputPortInterface { function handle(UserCreateInputData $inputData); } class UserCreateInteractor implements UserCreateInputPortInterfac { private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); interface UserCreateOutputPortInterface { function output(UserCreateOutputData $outputData); } class UserCreateOutputData { private $createdId; public function __construct(string $createdId) { $this->createdId = $createdId; } public function getCreatedId(): string { return $this->createdId; } } class UserCreatePresenter implements UserCreateOutputPor { private $middleware; public function __construct(ClarcMiddleware $middlew { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputD { $viewModel = new UserCreateViewModel($outputData $this->middleware->setData(view('view_resource', } } class UserCreateViewModel { private $createdId; public function __construct(UserCreateOutputData { $this->createdId = $source->getCreatedId(); } public function getCreatedId(): string { return $this->createdId; } }
  79. 216

  80. 227 227 /** * Class MyTestClass * @package nrslib */

    class MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; } /** * @param string $test * @param string $test2 */ public function test(string $test, string $test { } /** * */ private function test2() { $testField = 1; } } Programming
  81. 234 234 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define)

    { $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  82. 235 235 /** * Class MyTestClass * @package nrslib */

    class MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; } /** * @param string $test * @param string $test2 */ public function test(string $test, string $test2) { } /** * */ private function test2() { $testField = 1; } }
  83. 236 236 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define)

    { $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  84. 237 237 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define)

    { $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  85. 238 238 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define)

    { $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  86. 239 239 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define)

    { $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  87. 240 240 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?=

    "<?php" ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implem { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  88. 241 241 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?=

    "<?php" ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implem { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> } twig / smarty / blade 使えよ
  89. 242 242 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?=

    "<?php" ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implem { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> } twig / smarty / blade 使えよ それな
  90. 243 243 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?=

    "<?php" ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implem { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  91. 244 244 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?=

    "<?php" ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implem { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  92. 245 245 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?=

    "<?php" ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implem { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  93. 246 246 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?=

    "<?php" ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implem { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  94. 262 262 $classRenderer = new ClassRenderer(); $interfaceRenderer = new InterfaceRenderer();

    $presenter = new UseCaseCreateTestPresenter(); $controllerBuilder = new DefaultControllerSourceFileBuilder($classRenderer); $presenterBuilder = new DefaultPresenterSourceFileBuilder($classRenderer); $interactor = new UseCaseCreateInteractor( $presenter, $classRenderer, $interfaceRenderer, $controllerBuilder, $presenterBuilder); $namespace = 'nrslib¥¥Test'; $inputData = new UseCaseCreateInputData( new UseCaseCreateNamespaceData( $namespace . '¥¥A', $namespace . '¥¥B', $namespace . '¥¥C', $namespace . '¥¥D', $namespace . '¥¥E', $namespace . '¥¥F'), new UseCaseSchema('Test', 'MyAction'), [ new TypeAndName('string', 'inputStringField') ], [ new TypeAndName('string', 'outputStringField') ] ); $interactor->handle($inputData); $outputData = $presenter->outputData;
  95. 263 263 $classRenderer = new ClassRenderer(); $interfaceRenderer = new InterfaceRenderer();

    $presenter = new UseCaseCreateTestPresenter(); $controllerBuilder = new DefaultControllerSourceFileBuilder($classRenderer); $presenterBuilder = new DefaultPresenterSourceFileBuilder($classRenderer); $interactor = new UseCaseCreateInteractor( $presenter, $classRenderer, $interfaceRenderer, $controllerBuilder, $presenterBuilder); $namespace = 'nrslib¥¥Test'; $inputData = new UseCaseCreateInputData( new UseCaseCreateNamespaceData( $namespace . '¥¥A', $namespace . '¥¥B', $namespace . '¥¥C', $namespace . '¥¥D', $namespace . '¥¥E', $namespace . '¥¥F'), new UseCaseSchema('Test', 'MyAction'), [ new TypeAndName('string', 'inputStringField') ], [ new TypeAndName('string', 'outputStringField') ] ); $interactor->handle($inputData); $outputData = $presenter->outputData;
  96. 264 264 $classRenderer = new ClassRenderer(); $interfaceRenderer = new InterfaceRenderer();

    $presenter = new UseCaseCreateTestPresenter(); $controllerBuilder = new DefaultControllerSourceFileBuilder($classRenderer); $presenterBuilder = new DefaultPresenterSourceFileBuilder($classRenderer); $interactor = new UseCaseCreateInteractor( $presenter, $classRenderer, $interfaceRenderer, $controllerBuilder, $presenterBuilder); $namespace = 'nrslib¥¥Test'; $inputData = new UseCaseCreateInputData( new UseCaseCreateNamespaceData( $namespace . '¥¥A', $namespace . '¥¥B', $namespace . '¥¥C', $namespace . '¥¥D', $namespace . '¥¥E', $namespace . '¥¥F'), new UseCaseSchema('Test', 'MyAction'), [ new TypeAndName('string', 'inputStringField') ], [ new TypeAndName('string', 'outputStringField') ] ); $interactor->handle($inputData); $outputData = $presenter->outputData;
  97. 265 class UserController { private $inputPort; public function __construct(UserCreateInputPortInterface $inputPort)

    { $this->inputPort = $inputPort; } public function create(string $name, string $roleId) { $role = $this->convertRole($roleId); $inputData = new UserCreateInputData($name, $role); $this->inputPort->handle($inputData); } private function convertRole(string $roleId): string { switch ($roleId) { case 'admin': return UserRole::ADMIN; case 'member': return UserRole::MEMBER; default: throw new ¥Exception(); } } } class UserCreateInputData { private $name; private $roleId; public function __construct(string $name, string $roleId) { $this->name = $name; $this->roleId = $roleId; } public function getName(): string { return $this->name; } public function getRoleId(): string { return $this->roleId; } } interface UserCreateInputPortInterface { function handle(UserCreateInputData $inputData); } class UserCreateInteractor implements UserCreateInputPortInterfac { private $repository; private $outputPort; public function __construct( UserRepositoryInterface $repository, UserCreateOutputPortInterface $outputPort) { $this->repository = $repository; $this->outputPort = $outputPort; } public function handle(UserCreateInputData $inputData) { $id = uniqid(); $user = new User ( new UserId($id), new UserName($inputData->getName()), $this->getRole($inputData->getRole()) ); interface UserCreateOutputPortInterface { function output(UserCreateOutputData $outputData); } class UserCreateOutputData { private $createdId; public function __construct(string $createdId) { $this->createdId = $createdId; } public function getCreatedId(): string { return $this->createdId; } } class UserCreatePresenter implements UserCreateOutputPor { private $middleware; public function __construct(ClarcMiddleware $middlew { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputD { $viewModel = new UserCreateViewModel($outputData $this->middleware->setData(view('view_resource', } } class UserCreateViewModel { private $createdId; public function __construct(UserCreateOutputData { $this->createdId = $source->getCreatedId(); } public function getCreatedId(): string { return $this->createdId; } }
  98. 271 class UserController extends BaseController { public function create( UserCreateInputPortInterface

    $inputPort, Request $request) { $name = $request->input('name'); $roleId = $request->input('roleId'); $inputData = new UserCreateInputData($name, $roleId); $inputPort->handle($inputData); ... 戻り値を無くす } }
  99. 272 class UserController extends BaseController { public function create( UserCreateInputPortInterface

    $inputPort, Request $request) { $name = $request->input('name'); $roleId = $request->input('roleId'); $inputData = new UserCreateInputData($name, $roleId); $inputPort->handle($inputData); ... 戻り値を無くす } }
  100. 273 class UserController extends BaseController { public function create( UserCreateInputPortInterface

    $inputPort, Request $request) { $name = $request->input('name'); $roleId = $request->input('roleId'); $inputData = new UserCreateInputData($name, $roleId); $inputPort->handle($inputData); ... 戻り値を無くす } }
  101. 274 class UserController extends BaseController { public function create( UserCreateInputPortInterface

    $inputPort, Request $request) { $name = $request->input('name'); $roleId = $request->input('roleId'); $inputData = new UserCreateInputData($name, $roleId); $inputPort->handle($inputData); ... 戻り値を無くす } }
  102. 276 class UserCreatePresenter implements UserCreateOutputPortInterface { public function output(UserCreateOutputData $outputData)

    { ... どうにかしてビューを描画する } } こっちの方がむしろ Classic MVC に近い
  103. 281 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void { $this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } }
  104. 282 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void {$this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } } class UserCreatePresenter implements UserCreateOutputPortInterface { private $middleware; public function __construct(ClarcMiddleware $middleware) { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputData) { $viewModel = new UserCreateViewModel($outputData); $this->middleware->setData( view('user.create', compact('viewModel'))); } }
  105. 283 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void {$this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } } class UserCreatePresenter implements UserCreateOutputPortInterface { private $middleware; public function __construct(ClarcMiddleware $middleware) { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputData) { $viewModel = new UserCreateViewModel($outputData); $this->middleware->setData( view('user.create', compact('viewModel'))); } }
  106. 284 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void {$this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } } class UserCreatePresenter implements UserCreateOutputPortInterface { private $middleware; public function __construct(ClarcMiddleware $middleware) { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputData) { $viewModel = new UserCreateViewModel($outputData); $this->middleware->setData( view('user.create', compact('viewModel'))); } }
  107. 285 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void {$this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } } class UserCreatePresenter implements UserCreateOutputPortInterface { private $middleware; public function __construct(ClarcMiddleware $middleware) { $this->middleware = $middleware; } public function output(UserCreateOutputData $outputData) { $viewModel = new UserCreateViewModel($outputData); $this->middleware->setData( view('user.create', compact('viewModel'))); } }
  108. 286 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void { $this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } }
  109. 287 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void { $this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } }
  110. 288 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void { $this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } }
  111. 289 class ClarcMiddleWare { /** @var mixed */ private $data;

    /** @var Router */ private $router; public function __construct(Router $router) { $this->router = $router; } public function setData($data): void { $this->data = $data; } public function handle($request, Closure $next) { $response = $next($request); if ($this->data === null) { return $response; } return $this->router->prepareResponse( $this->router->getCurrentRequest(), $this->data); } }
  112. 297 class ClarcInitializeCommand extends ClarcCommand { protected $signature = 'clarc:init';

    public function handle() { $this->title('Initialize clarc'); $middlewareFilePath = LaravelConfig::DIR_MIDDLEWARE . 'ClarcMiddl $this->info('Creating file ' . $middlewareFilePath); file_put_contents($middlewareFilePath, ClarcModuleCodes::$middleW $this->info('Wrote ' . realpath($middlewareFilePath)); $this->newline(); $clarcProviderFilePath = LaravelConfig::DIR_PROVIDER . 'ClarcProv $this->info('Creating file' . $clarcProviderFilePath); file_put_contents($clarcProviderFilePath, ClarcModuleCodes::$clar $this->info('Wrote ' . realpath($clarcProviderFilePath)); $this->newline(); $this->info('Please append ClarcProvider to app.php'); } }
  113. 298 class ClarcInitializeCommand extends ClarcCommand { protected $signature = 'clarc:init';

    public function handle() { $this->title('Initialize clarc'); $middlewareFilePath = LaravelConfig::DIR_MIDDLEWARE . 'ClarcMiddl $this->info('Creating file ' . $middlewareFilePath); file_put_contents($middlewareFilePath, ClarcModuleCodes::$middleW $this->info('Wrote ' . realpath($middlewareFilePath)); $this->newline(); $clarcProviderFilePath = LaravelConfig::DIR_PROVIDER . 'ClarcProv $this->info('Creating file' . $clarcProviderFilePath); file_put_contents($clarcProviderFilePath, ClarcModuleCodes::$clar $this->info('Wrote ' . realpath($clarcProviderFilePath)); $this->newline(); $this->info('Please append ClarcProvider to app.php'); } }
  114. 301

  115. 302

  116. 303

  117. 304 class ClarcMakeCommand extends ClarcCommand { public function handle() {

    $this->title('Make usecase'); $this->info('Please input your controller name.'); $controllerName = $this->need('controller name'); $controllerName = ucfirst($controllerName); $this->info('Please input your action name.'); $actionName = $this->need('action name.'); $actionName = ucfirst($actionName); $schema = new UseCaseSchema($controllerName, $actionName); $objectCreatePresenter = new ClarcMakeCommandObjectCreatePresenter($this, $schema); $alreadyRegistered = !$this->checkFiles($controllerName, $actionName, $objectCreateP if ($alreadyRegistered) { $this->info('process ended.'); return; } $this->info('Please select input data fields'); $inputDataFields = $this->askFields(); $this->info('Please select output data fields'); $outputDataFields = $this->askFields(); $this->createClarcObjects($objectCreatePresenter, $controllerName, $actionName, $inp $this->registerDependency($controllerName, $actionName); $this->info('process ended.');
  118. 305 private function createClarcObjects( ClarcMakeCommandObjectCreatePresenter $objectCreatePresenter, string $controllerName, string $actionName,

    array $inputDataFields, array $outputDataFields) { $objectCreateInteractor = new ClarcObjectCreateInteractor( $objectCreatePresenter, new ClassRenderer(), new InterfaceRenderer() ); $currentControllerContent = $this->getCurrentControllerContent( $controllerName); $objectCreateInputData = new ClarcObjectCreateInputData( $controllerName, $currentControllerContent, $actionName, $inputDataFields, $outputDataFields ); $objectCreateInteractor->handle($objectCreateInputData); }
  119. 306 private function createClarcObjects( ClarcMakeCommandObjectCreatePresenter $objectCreatePresenter, string $controllerName, string $actionName,

    array $inputDataFields, array $outputDataFields) { $objectCreateInteractor = new ClarcObjectCreateInteractor( $objectCreatePresenter, new ClassRenderer(), new InterfaceRenderer() ); $currentControllerContent = $this->getCurrentControllerContent( $controllerName); $objectCreateInputData = new ClarcObjectCreateInputData( $controllerName, $currentControllerContent, $actionName, $inputDataFields, $outputDataFields ); $objectCreateInteractor->handle($objectCreateInputData); }
  120. 307 private function createClarcObjects( ClarcMakeCommandObjectCreatePresenter $objectCreatePresenter, string $controllerName, string $actionName,

    array $inputDataFields, array $outputDataFields) { $objectCreateInteractor = new ClarcObjectCreateInteractor( $objectCreatePresenter, new ClassRenderer(), new InterfaceRenderer() ); $currentControllerContent = $this->getCurrentControllerContent( $controllerName); $objectCreateInputData = new ClarcObjectCreateInputData( $controllerName, $currentControllerContent, $actionName, $inputDataFields, $outputDataFields ); $objectCreateInteractor->handle($objectCreateInputData); }
  121. 308 private function createClarcObjects( ClarcMakeCommandObjectCreatePresenter $objectCreatePresenter, string $controllerName, string $actionName,

    array $inputDataFields, array $outputDataFields) { $objectCreateInteractor = new ClarcObjectCreateInteractor( $objectCreatePresenter, new ClassRenderer(), new InterfaceRenderer() ); $currentControllerContent = $this->getCurrentControllerContent( $controllerName); $objectCreateInputData = new ClarcObjectCreateInputData( $controllerName, $currentControllerContent, $actionName, $inputDataFields, $outputDataFields ); $objectCreateInteractor->handle($objectCreateInputData); }
  122. 310 class ClarcProvider extends ServiceProvider { public function register() {

    $this->app->singleton(ClarcMiddleWare::class); $this->registerUseCases(); } private function registerUseCases() { // TestMyAction $this->app->bind( ¥packages¥InputPorts¥Test¥MyAction¥TestMyActionInputPortInterface::class, ¥packages¥Interactors¥Test¥TestMyActionInteractor::class); $this->app->bind( ¥packages¥OutputPorts¥Test¥MyAction¥TestMyActionOutputPortInterface::class, ¥App¥Http¥Presenters¥Test¥TestMyActionPresenter::class); // UserCreate $this->app->bind( ¥packages¥InputPorts¥User¥Create¥UserCreateInputPortInterface::class, ¥packages¥Interactors¥User¥UserCreateInteractor::class); $this->app->bind( ¥packages¥OutputPorts¥User¥Create¥UserCreateOutputPortInterface::class, ¥App¥Http¥Presenters¥User¥UserCreatePresenter::class); } }
  123. 319

  124. 320

  125. 321

  126. 328 class Startup { public function configureService( ServiceCollection $serviceCollection) {

    $this->registerUsecases($serviceCollection); } private function registerUseCases( ServiceCollection $serviceCollection) { // UserCreate $serviceCollection->addTransient(UserCreateController::class); $serviceCollection->addTransient( UserCreateInputPortInterface::class, UserCreateInteractor::class); $serviceCollection->addTransient( UserCreateOutputPortInterface::class, UserCreatePresenter::class); } }
  127. 330 private function getControllerName($server) { $root = $server['DOCUMENT_ROOT']; $url =

    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $tokens = explode('/', $url); $count = count($tokens); if (!isset($tokens[1])) { throw new ¥Exception($tokens); } $top = ucfirst($tokens[1]); if (!isset($tokens[2])) { throw new ¥Exception($tokens[1]); } $second = ucfirst($tokens[2]); $path = $root . '/app/InterfaceAdapters/Controllers/' . $top . '/' . if ($count === 3 && file_exists($path)) { return 'App¥¥InterfaceAdapters¥¥Controllers¥¥' . $top . '¥¥' . $s } return null; }
  128. 331 private function getControllerName($server) { $root = $server['DOCUMENT_ROOT']; $url =

    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $tokens = explode('/', $url); $count = count($tokens); if (!isset($tokens[1])) { throw new ¥Exception($tokens); } $top = ucfirst($tokens[1]); if (!isset($tokens[2])) { throw new ¥Exception($tokens[1]); } $second = ucfirst($tokens[2]); $path = $root . '/app/InterfaceAdapters/Controllers/' . $top . '/' . if ($count === 3 && file_exists($path)) { return 'App¥¥InterfaceAdapters¥¥Controllers¥¥' . $top . '¥¥' . $s } return null; }
  129. 332 private function getControllerName($server) { $root = $server['DOCUMENT_ROOT']; $url =

    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $tokens = explode('/', $url); $count = count($tokens); if (!isset($tokens[1])) { throw new ¥Exception($tokens); } $top = ucfirst($tokens[1]); if (!isset($tokens[2])) { throw new ¥Exception($tokens[1]); } $second = ucfirst($tokens[2]); $path = $root . '/app/InterfaceAdapters/Controllers/' . $top . '/' . if ($count === 3 && file_exists($path)) { return 'App¥¥InterfaceAdapters¥¥Controllers¥¥' . $top . '¥¥' . $s } return null; }
  130. 333 private function getControllerName($server) { $root = $server['DOCUMENT_ROOT']; $url =

    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $tokens = explode('/', $url); $count = count($tokens); if (!isset($tokens[1])) { throw new ¥Exception($tokens); } $top = ucfirst($tokens[1]); if (!isset($tokens[2])) { throw new ¥Exception($tokens[1]); } $second = ucfirst($tokens[2]); $path = $root . '/app/InterfaceAdapters/Controllers/' . $top . '/' . if ($count === 3 && file_exists($path)) { return 'App¥¥InterfaceAdapters¥¥Controllers¥¥' . $top . '¥¥' . $s } S return null; } http://sample.com/{controller}/{action} 以外認めない