Skip to content

Commit

Permalink
updated composer dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
icomefromthenet committed Oct 17, 2012
1 parent 380c8f7 commit a97cb88
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 7 deletions.
19 changes: 19 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2012 Lewis Dyer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{
"name": "icomefromthenet/reverse-regex",
"description": "Convert Regular Expressions into text, for testing",
"keywords": ["regex","testing","test data","generator"],
"homepage": "http://github.com/icomefromthenet/ReverseRegex",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Lewis Dyer",
"email": "getintouch@icomefromthenet.com",
"homepage": "www.icomefromthenet.com"
}
],
"require": {
"doctrine/common" : "2.3.0",
"graphgroup/object" : "dev-master",
"graphgroup/template" : "dev-master",
"patchwork/utf8" : "dev-master"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/ReverseRegex/Generator/LiteralScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LiteralScope extends Scope
* @param string $label
* @param Node $parent
*/
public function __construct($label = self::TEMPLATE_LABEL)
public function __construct($label = 'label')
{
parent::__construct($label);

Expand Down
193 changes: 193 additions & 0 deletions src/ReverseRegex/Generator/Node.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?php
namespace ReverseRegex\Generator;

use \ArrayObject;
use \SplObjectStorage;
use \ArrayAccess;
use \Countable;
use \Iterator;

/**
* Base to all Generator Scopes
*
* @author Lewis Dyer <getintouch@icomefromthenet.com>
* @since 0.0.1
*/
class Node implements ArrayAccess, Countable, Iterator
{
/**
* @var string name of the node
*/
protected $label;

/**
* @var ArrayObject container for node metadata
*/
protected $attrs;

/**
* @var SplObjectStorage container for node relationships
*/
protected $links;

/**
* Class Constructor
*
* @access public
* @param string $label
*/
public function __construct($label = 'node')
{
$this->attrs = new ArrayObject();
$this->links = new SplObjectStorage();

$this->setLabel($label);
}

/**
* Fetch the nodes label
*
* @access public
* @return string the nodes label
*/
public function getLabel()
{
return $this->label;
}

/**
* Sets the node label
*
* @access public
* @param string $label the nodes label
*/
public function setLabel($label)
{
if (!(is_scalar($label) || is_null($label))) {
return false;
}

$this->label = $label;
}


/**
* Attach a node
*
* @access public
* @param Node $node the node to attach
* @return Node
*/
public function &attach(Node $node)
{
$this->links->attach($node);

return $this;
}

/**
* Detach a node
*
* @access public
* @return Node
* @param Node $node the node to remove
*/
public function &detach(Node $node)
{
foreach ($this->links as $linked_node) {
if ($linked_node == $node) {
$this->links->detach($node);
}
}

return $this;
}

/**
* Search for node in its relations
*
* @access public
* @return boolean true if found
* @param Node $node the node to search for
*/
public function contains(Node $node)
{
foreach ($this->links as $linked_node) {
if ($linked_node == $node) {
return true;
}
}

return false;
}

/**
* Apply a closure to all relations
*
* @access public
* @param Closer the function to apply
*/
public function map(Closure $function)
{
foreach ($this->links as $node) {
$function($node);
}
}

//------------------------------------------------------------------
# Countable

public function count()
{
return count($this->links);
}

//------------------------------------------------------------------
# Iterator

public function current()
{
return $this->links->current();
}
public function key()
{
return $this->links->key();
}
public function next()
{
return $this->links->next();
}
public function rewind()
{
return $this->links->rewind();
}
public function valid()
{
return $this->links->valid();
}

//------------------------------------------------------------------
# ArrayAccess Implementation

public function offsetGet($key)
{
return $this->attrs->offsetGet($key);
}

public function offsetSet($key, $value)
{
$this->attrs->offsetSet($key, $value);
}

public function offsetExists($key)
{
return $this->attrs->offsetExists($key);
}

public function offsetUnset($key)
{
return $this->attrs->offsetUnset($key);
}
}

/* End of Class */
4 changes: 1 addition & 3 deletions src/ReverseRegex/Generator/Scope.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace ReverseRegex\Generator;


use GraphGroup\Object\Node;
use PHPStats\Generator\GeneratorInterface;
use ReverseRegex\Exception as GeneratorException;

Expand All @@ -25,7 +23,7 @@ class Scope extends Node implements ContextInterface, RepeatInterface, Alternate
/**
* Class Constructor
*/
public function __construct($label = self::TEMPLATE_LABEL)
public function __construct($label = 'node')
{
parent::__construct($label);

Expand Down
2 changes: 1 addition & 1 deletion src/ReverseRegex/Test/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testScopeImplementsContextInterface()
public function testScopeExtendsNode()
{
$scope = new Scope('scope1');
$this->assertInstanceOf('GraphGroup\Object\Node',$scope);
$this->assertInstanceOf('ReverseRegex\Generator\Node',$scope);
}

public function testScopeImplementsAlternateInterface()
Expand Down

0 comments on commit a97cb88

Please sign in to comment.