This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joan Fabrégat
committed
Oct 15, 2018
1 parent
146b9ca
commit ba2a127
Showing
4 changed files
with
251 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
// | ||
// +---------------------------------------------------------------------+ | ||
// | CODE INC. SOURCE CODE | | ||
// +---------------------------------------------------------------------+ | ||
// | Copyright (c) 2018 - Code Inc. SAS - All Rights Reserved. | | ||
// | Visit https://www.codeinc.fr for more information about licensing. | | ||
// +---------------------------------------------------------------------+ | ||
// | NOTICE: All information contained herein is, and remains the | | ||
// | property of Code Inc. SAS. The intellectual and technical concepts | | ||
// | contained herein are proprietary to Code Inc. SAS are protected by | | ||
// | trade secret or copyright law. Dissemination of this information or | | ||
// | reproduction of this material is strictly forbidden unless prior | | ||
// | written permission is obtained from Code Inc. SAS. | | ||
// +---------------------------------------------------------------------+ | ||
// | ||
// Author: Joan Fabrégat <[email protected]> | ||
// Date: 15/10/2018 | ||
// Project: CollectionInterface | ||
// | ||
declare(strict_types=1); | ||
namespace CodeInc\CollectionInterface; | ||
|
||
/** | ||
* Class AbstractArrayCollection | ||
* | ||
* @package CodeInc\CollectionInterface | ||
* @author Joan Fabrégat <[email protected]> | ||
*/ | ||
abstract class AbstractArrayCollection implements CollectionInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $array = []; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $iteratorPosition = 0; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function rewind():void | ||
{ | ||
$this->iteratorPosition = 0; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function next():void | ||
{ | ||
$this->iteratorPosition++; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function key():int | ||
{ | ||
return $this->iteratorPosition; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return bool | ||
*/ | ||
public function valid():bool | ||
{ | ||
return array_key_exists($this->iteratorPosition, $this->array); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function current() | ||
{ | ||
return $this->array[$this->iteratorPosition]; | ||
} | ||
} |
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,89 @@ | ||
<?php | ||
// | ||
// +---------------------------------------------------------------------+ | ||
// | CODE INC. SOURCE CODE | | ||
// +---------------------------------------------------------------------+ | ||
// | Copyright (c) 2018 - Code Inc. SAS - All Rights Reserved. | | ||
// | Visit https://www.codeinc.fr for more information about licensing. | | ||
// +---------------------------------------------------------------------+ | ||
// | NOTICE: All information contained herein is, and remains the | | ||
// | property of Code Inc. SAS. The intellectual and technical concepts | | ||
// | contained herein are proprietary to Code Inc. SAS are protected by | | ||
// | trade secret or copyright law. Dissemination of this information or | | ||
// | reproduction of this material is strictly forbidden unless prior | | ||
// | written permission is obtained from Code Inc. SAS. | | ||
// +---------------------------------------------------------------------+ | ||
// | ||
// Author: Joan Fabrégat <[email protected]> | ||
// Date: 15/10/2018 | ||
// Project: CollectionInterface | ||
// | ||
declare(strict_types=1); | ||
namespace CodeInc\CollectionInterface; | ||
|
||
/** | ||
* Class AbstractAssocArrayCollection | ||
* | ||
* @package CodeInc\CollectionInterface | ||
* @author Joan Fabrégat <[email protected]> | ||
*/ | ||
abstract class AbstractAssocArrayCollection implements CollectionInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $array = []; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
private $iteratorPosition; | ||
|
||
/** | ||
* @var array|null | ||
*/ | ||
private $iteratorKeys; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function rewind():void | ||
{ | ||
$this->iteratorPosition = 0; | ||
$this->iteratorKeys = array_keys($this->array); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function next():void | ||
{ | ||
$this->iteratorPosition++; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function key():int | ||
{ | ||
return $this->iteratorKeys[$this->iteratorPosition]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return bool | ||
*/ | ||
public function valid():bool | ||
{ | ||
return array_key_exists($this->iteratorPosition, $this->iteratorKeys) | ||
&& array_key_exists($this->iteratorKeys[$this->iteratorPosition], $this->array); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function current() | ||
{ | ||
return $this->array[$this->iteratorKeys[$this->iteratorPosition]]; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
// | ||
// +---------------------------------------------------------------------+ | ||
// | CODE INC. SOURCE CODE | | ||
// +---------------------------------------------------------------------+ | ||
// | Copyright (c) 2018 - Code Inc. SAS - All Rights Reserved. | | ||
// | Visit https://www.codeinc.fr for more information about licensing. | | ||
// +---------------------------------------------------------------------+ | ||
// | NOTICE: All information contained herein is, and remains the | | ||
// | property of Code Inc. SAS. The intellectual and technical concepts | | ||
// | contained herein are proprietary to Code Inc. SAS are protected by | | ||
// | trade secret or copyright law. Dissemination of this information or | | ||
// | reproduction of this material is strictly forbidden unless prior | | ||
// | written permission is obtained from Code Inc. SAS. | | ||
// +---------------------------------------------------------------------+ | ||
// | ||
// Author: Joan Fabrégat <[email protected]> | ||
// Date: 15/10/2018 | ||
// Project: CollectionInterface | ||
// | ||
declare(strict_types=1); | ||
namespace CodeInc\CollectionInterface; | ||
|
||
/** | ||
* Class AbstractCountableArrayCollection | ||
* | ||
* @package CodeInc\CollectionInterface | ||
* @author Joan Fabrégat <[email protected]> | ||
*/ | ||
class AbstractCountableArrayCollection extends AbstractArrayCollection implements CountableCollectionInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
* @return int | ||
*/ | ||
public function count():int | ||
{ | ||
return count($this->array); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
// | ||
// +---------------------------------------------------------------------+ | ||
// | CODE INC. SOURCE CODE | | ||
// +---------------------------------------------------------------------+ | ||
// | Copyright (c) 2018 - Code Inc. SAS - All Rights Reserved. | | ||
// | Visit https://www.codeinc.fr for more information about licensing. | | ||
// +---------------------------------------------------------------------+ | ||
// | NOTICE: All information contained herein is, and remains the | | ||
// | property of Code Inc. SAS. The intellectual and technical concepts | | ||
// | contained herein are proprietary to Code Inc. SAS are protected by | | ||
// | trade secret or copyright law. Dissemination of this information or | | ||
// | reproduction of this material is strictly forbidden unless prior | | ||
// | written permission is obtained from Code Inc. SAS. | | ||
// +---------------------------------------------------------------------+ | ||
// | ||
// Author: Joan Fabrégat <[email protected]> | ||
// Date: 15/10/2018 | ||
// Project: CollectionInterface | ||
// | ||
declare(strict_types=1); | ||
namespace CodeInc\CollectionInterface; | ||
|
||
/** | ||
* Class AbstractCountableAssocArrayCollection | ||
* | ||
* @package CodeInc\CollectionInterface | ||
* @author Joan Fabrégat <[email protected]> | ||
*/ | ||
class AbstractCountableAssocArrayCollection extends AbstractAssocArrayCollection implements CountableCollectionInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
* @return int | ||
*/ | ||
public function count():int | ||
{ | ||
return count($this->array); | ||
} | ||
} |