This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#45 Add rootline and rootline item class
- Loading branch information
Julian Kleinhans
committed
Dec 13, 2016
1 parent
5f11183
commit 4fbac73
Showing
2 changed files
with
82 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,44 @@ | ||
<?php | ||
|
||
namespace StackFormation\PreProcessor; | ||
|
||
/** | ||
* Class Rootline | ||
* | ||
* The rootline shows gives the transformers access to the parent objects (all generations) | ||
* since sometimes you need to change things outside of the current value (e.g. when replacing the whole node) | ||
*/ | ||
class Rootline extends \ArrayObject { | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getKeys() { | ||
return array_keys($this->getArrayCopy()); | ||
} | ||
|
||
/** | ||
* @param $index | ||
* @return mixed | ||
*/ | ||
public function indexGet($index) { | ||
$keys = $this->getKeys(); | ||
return $this->offsetGet($keys[$index]); | ||
} | ||
|
||
public function removeLast() { | ||
$keys = $this->getKeys(); | ||
|
||
// TODO | ||
@$this->offsetUnset($keys[$this->count()]); | ||
} | ||
|
||
/** | ||
* @param int $generation | ||
* @return mixed | ||
*/ | ||
public function parent($generation = 1) { | ||
$keys = $this->getKeys(); | ||
return $this->offsetGet($keys[$this->count() - $generation]); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace StackFormation\PreProcessor; | ||
|
||
/** | ||
* Class RootlineItem | ||
* | ||
* Since you not only need the reference to the parent(s) but also their key in relation to their parent | ||
* (e.g. in case you need to delete them), this rootline item represents the item itself (value) and the position (key) | ||
*/ | ||
class RootlineItem { | ||
|
||
protected $key; | ||
protected $value; | ||
|
||
/** | ||
* @param string $key | ||
* @param mixed $value | ||
*/ | ||
public function __construct($key, $value) { | ||
$this->key = $key; | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKey() { | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getValue() { | ||
return $this->value; | ||
} | ||
} |