diff --git a/docs/demo/1.csrf/run.php b/docs/demo/1.csrf/run.php index a10ee6e..c172253 100644 --- a/docs/demo/1.csrf/run.php +++ b/docs/demo/1.csrf/run.php @@ -20,4 +20,3 @@ echo 'Anti CSRF DOES NOT works !' . PHP_EOL; //$works = $controller->response['body'] == 'create bear'; //echo ($works ? 'It works!' : 'It DOES NOT work!') . PHP_EOL; - diff --git a/src/AbstractAuraForm.php b/src/AbstractAuraForm.php index 2e536e5..3886744 100644 --- a/src/AbstractAuraForm.php +++ b/src/AbstractAuraForm.php @@ -18,29 +18,37 @@ abstract class AbstractAuraForm extends Form implements FormInterface { /** - * @\Ray\Di\Di\Inject - * * @param BuilderInterface $builder An object to build input objects. * @param FilterInterface $filter A filter object for this fieldset. * @param object $options An arbitrary options object for use when setting * up inputs and filters. + * @\Ray\Di\Di\Inject */ - public function parentConstruct( + public function setBaseDependencies( BuilderInterface $builder, FilterInterface $filter, + HelperLocatorFactory $factory, $options = null ) { $this->builder = $builder; $this->filter = $filter; $this->options = $options; + $this->helper = $factory->newInstance(); + } + + public function __construct() + { } /** - * @PostConstruct + * @\Ray\Di\Di\PostConstruct */ public function postConstruct() { $this->init(); + if ($this->antiCsrf instanceof AntiCsrfInterface) { + $this->setAntiCsrf($this->antiCsrf); + } } /** @@ -55,14 +63,6 @@ public function postConstruct() */ protected $string = '
'; - /** - * @Inject - */ - public function setFormHelper(HelperLocatorFactory $factory) - { - $this->helper = $factory->newInstance(); - } - /** * @param AntiCsrfInterface $antiCsrf */ diff --git a/src/AbstractForm.php b/src/AbstractForm.php index d316b65..7ac4998 100644 --- a/src/AbstractForm.php +++ b/src/AbstractForm.php @@ -13,11 +13,7 @@ use Aura\Input\AntiCsrfInterface; use Aura\Input\Builder; use Aura\Input\BuilderInterface; -use Aura\Input\Filter; -use Aura\Input\FilterInterface; use Aura\Input\Form; -use Ray\Di\Di\Inject; -use Ray\Di\Di\PostConstruct; abstract class AbstractForm extends Form implements FormInterface { @@ -35,8 +31,10 @@ abstract class AbstractForm extends Form implements FormInterface * @param BuilderInterface $builder * @param FilterFactory $filterFactory * @param HelperLocatorFactory $helperFactory + * + * @\Ray\Di\Di\Inject */ - public function __construct( + public function setBaseDependencies( BuilderInterface $builder = null, FilterFactory $filterFactory = null, HelperLocatorFactory $helperFactory = null @@ -46,12 +44,19 @@ public function __construct( $this->helper = $helperFactory ? $helperFactory->newInstance() : (new HelperLocatorFactory)->newInstance(); } + public function __construct() + { + } + /** - * @PostConstruct + * @\Ray\Di\Di\PostConstruct */ public function postConstruct() { $this->init(); + if ($this->antiCsrf instanceof AntiCsrfInterface) { + $this->setAntiCsrf($this->antiCsrf); + } } /** diff --git a/src/SetAntiCsrfTrait.php b/src/SetAntiCsrfTrait.php index b70d636..528b0db 100644 --- a/src/SetAntiCsrfTrait.php +++ b/src/SetAntiCsrfTrait.php @@ -10,6 +10,11 @@ trait SetAntiCsrfTrait { + /** + * @var AntiCsrfInterface + */ + protected $antiCsrf; + /** * @param AntiCsrfInterface $antiCsrf * @@ -17,6 +22,6 @@ trait SetAntiCsrfTrait */ public function injectAntiCsrf(AntiCsrfInterface $antiCsrf) { - $this->setAntiCsrf($antiCsrf); + $this->antiCsrf = $antiCsrf; } } diff --git a/tests/AbstractAuraFormTest.php b/tests/AbstractAuraFormTest.php index 7574651..e3d5c26 100644 --- a/tests/AbstractAuraFormTest.php +++ b/tests/AbstractAuraFormTest.php @@ -16,8 +16,9 @@ class AbstractAuraFormTest extends \PHPUnit_Framework_TestCase public function setUp() { parent::setUp(); - $this->form = new FakeForm(new Builder, new Filter); - $this->form->setFormHelper(new HelperLocatorFactory); + $this->form = new FakeForm; + $this->form->setBaseDependencies(new Builder, new Filter, new HelperLocatorFactory); + $this->form->postConstruct(); } public function testForm() diff --git a/tests/AbstractFormTest.php b/tests/AbstractFormTest.php index ff2620d..d600a2f 100644 --- a/tests/AbstractFormTest.php +++ b/tests/AbstractFormTest.php @@ -16,7 +16,8 @@ class AbstractFormTest extends \PHPUnit_Framework_TestCase public function setUp() { parent::setUp(); - $this->form = new FakeNameForm(new Builder, new FilterFactory, new HelperLocatorFactory); + $this->form = new FakeNameForm; + $this->form->setBaseDependencies(new Builder, new FilterFactory, new HelperLocatorFactory); } public function testSubmit() diff --git a/tests/AuraInputInterceptorTest.php b/tests/AuraInputInterceptorTest.php index 96dbb87..61afbd7 100644 --- a/tests/AuraInputInterceptorTest.php +++ b/tests/AuraInputInterceptorTest.php @@ -45,14 +45,25 @@ public function getMethodInvocation($method, array $submit, FailureHandlerInterf public function getController(array $submit) { $controller = new FakeController; - $fakeForm = new FakeForm(new Builder, new Filter); + $fakeForm = $this->getFakeForm(); $fakeForm->setSubmit($submit); - $fakeForm->setFormHelper(new HelperLocatorFactory); $controller->setForm($fakeForm); return $controller; } + /** + * @return FakeForm + */ + private function getFakeForm() + { + $fakeForm = new FakeForm; + $fakeForm->setBaseDependencies(new Builder, new Filter, new HelperLocatorFactory); + $fakeForm->postConstruct(); + + return $fakeForm; + } + public function proceed($controller) { $invocation = new ReflectiveMethodInvocation( @@ -103,7 +114,8 @@ public function testInvalidFormPropertyException() { $this->setExpectedException(InvalidOnFailureMethod::class); $controller = new FakeInvalidController3; - $controller->setForm(new FakeForm(new Builder, new Filter)); + $fakeForm = $this->getFakeForm(); + $controller->setForm($fakeForm); $this->proceed($controller); } diff --git a/tests/AuraInputModuleTest.php b/tests/AuraInputModuleTest.php index 0ccb122..a667feb 100644 --- a/tests/AuraInputModuleTest.php +++ b/tests/AuraInputModuleTest.php @@ -23,7 +23,7 @@ public function setUp() public function testAuraInputModule() { - $injector = new Injector(new FakeModule); + $injector = new Injector(new FakeModule, __DIR__ . '/tmp'); $controller = $injector->getInstance(FakeController::class); $this->assertInstanceOf(WeavedInterface::class, $controller); } diff --git a/tests/VndErrorHandlerTest.php b/tests/VndErrorHandlerTest.php index 67bb0ce..d23709d 100644 --- a/tests/VndErrorHandlerTest.php +++ b/tests/VndErrorHandlerTest.php @@ -15,7 +15,7 @@ class VndErrorHandlerTest extends \PHPUnit_Framework_TestCase public function setUp() { parent::setUp(); - $this->controller = (new Injector(new FakeVndErrorModule))->getInstance(FakeController::class); + $this->controller = (new Injector(new FakeVndErrorModule, __DIR__ . '/tmp'))->getInstance(FakeController::class); } public function testValidationException()