-
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.
all registries are now by reference, removes set & adds stack
- Loading branch information
Showing
12 changed files
with
214 additions
and
282 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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
<?php | ||
|
||
namespace Chevron\Containers; | ||
/** | ||
* implementation of a list -- a hybrid of a queue and a stack using redis-like | ||
* methods of left/right push/pop | ||
* | ||
* @package Chevron\Container | ||
*/ | ||
class Stack extends Registry implements StackInterface { | ||
|
||
/** | ||
* push values to our list | ||
* @param mixed $value | ||
*/ | ||
public function push($value){ | ||
array_push($this->map, $value); | ||
} | ||
|
||
/** | ||
* pop values off our array | ||
* @return mixed | ||
*/ | ||
public function pop(){ | ||
if($this->count()){ | ||
return array_pop($this->map); | ||
} | ||
} | ||
|
||
/** | ||
* view the next item in the stack | ||
*/ | ||
public function peek($n = 1) { | ||
if($this->isEmpty() || $n > $this->count() ){ | ||
return null; | ||
} | ||
return $this->map[ $this->count() - $n ]; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
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,23 @@ | ||
<?php | ||
|
||
namespace Chevron\Containers; | ||
/** | ||
* establishes the minimum signature of Chevron\Containers\Registry | ||
* | ||
* @package Chevron\Container | ||
*/ | ||
interface StackInterface extends RegistryInterface { | ||
|
||
/** | ||
* push values to our list | ||
* @param mixed $value | ||
*/ | ||
public function push($value); | ||
|
||
/** | ||
* shift values off our list | ||
* @return mixed | ||
*/ | ||
public function pop(); | ||
|
||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace Chevron\Containers\Traits; | ||
|
||
trait FilterTrait { | ||
|
||
abstract function get($key); | ||
|
||
abstract function set($key, $val); | ||
|
||
public function filter($name, callable $callback = null){ | ||
$value = $this->get($name); | ||
if($value != null && $callback){ | ||
$value = call_user_func($callback, $value); | ||
$this->set($name, $value); | ||
} | ||
return $value; | ||
} | ||
} |
Oops, something went wrong.