Skip to content

Commit 0eade0f

Browse files
committed
Added getArrayCopy() to Auth
1 parent 6810512 commit 0eade0f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

module/Auth/src/Auth/Controller/RegistrationController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ class RegistrationController extends AbstractActionController
2222
public function indexAction()
2323
{
2424
// A test instantiation to make sure it works. Not used in the application. You can remove the next line
25-
$myValidator = new ConfirmPassword();
25+
// $myValidator = new ConfirmPassword();
2626
$form = new RegistrationForm();
2727
$form->get('submit')->setValue('Register');
2828

2929
$request = $this->getRequest();
3030
if ($request->isPost()) {
3131
$form->setInputFilter(new RegistrationFilter($this->getServiceLocator()));
3232
$form->setData($request->getPost());
33-
if ($form->isValid()) {
33+
if ($form->isValid()) {
3434
$data = $form->getData();
3535
$data = $this->prepareData($data);
3636
$auth = new Auth();
3737
$auth->exchangeArray($data);
38+
3839
/*
3940
// this is replaced by
4041
// 1) Manualy composing (wiring) the objects
@@ -52,7 +53,8 @@ public function indexAction()
5253
echo '<pre>';
5354
var_dump($user7);
5455
echo '</pre>';
55-
*/
56+
*/
57+
5658
// OR
5759
// 2) Using the service Locator
5860
$this->getUsersTable()->saveUser($auth);

module/Auth/src/Auth/Model/Auth.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Auth implements InputFilterAwareInterface
2323
public $usr_registration_token;
2424
public $usr_email_confirmed;
2525

26+
// Hydration
2627
// ArrayObject, or at least implement exchangeArray. For Zend\Db\ResultSet\ResultSet to work
2728
public function exchangeArray($data)
2829
{
@@ -41,6 +42,14 @@ public function exchangeArray($data)
4142
$this->usr_registration_token = (!empty($data['usr_registration_token'])) ? $data['usr_registration_token'] : null;
4243
$this->usr_email_confirmed = (isset($data['usr_email_confirmed'])) ? $data['usr_email_confirmed'] : null;
4344
}
45+
46+
// Extraction. The Registration from the tutorial works even without it.
47+
// The standard Hydrator of the Form expects getArrayCopy to be able to bind
48+
public function getArrayCopy()
49+
{
50+
return get_object_vars($this);
51+
}
52+
4453

4554
protected $inputFilter;
4655

module/Auth/src/Auth/Model/UsersTable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public function saveUser(Auth $auth)
8080
'usr_registration_token'=> $auth->usr_registration_token,
8181
'usr_email_confirmed' => $auth->usr_email_confirmed,
8282
);
83+
// If there is a method getArrayCopy() defined in Auth you can simply call it.
84+
// $data = $auth->getArrayCopy();
8385

8486
$usr_id = (int)$auth->usr_id;
8587
if ($usr_id == 0) {

0 commit comments

Comments
 (0)