Skip to content

Instantly share code, notes, and snippets.

@paulosborne
Forked from skl/gist:2301078
Created April 4, 2012 13:52
Show Gist options
  • Save paulosborne/2301238 to your computer and use it in GitHub Desktop.
Save paulosborne/2301238 to your computer and use it in GitHub Desktop.
AssertionTuple with DataSetValue stack
<?php
class DataSetValue
{
const ALPHA_LOWER = 'abcdefghijklmnopqrstuvwxyz';
const ALPHA_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const ALPHA_NUMERIC = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const SYMBOLS = '!@£$%^&*()-=';
const SECURITY_XSS = "'';!--\"<XSS>=&{()}";
/**
* Data
*
* @access protected
* @var $data
*/
protected $data;
/**
* Data Length
*
* @var $dataLength;
* @access protected
*/
protected $dataLength;
public function __construct($data = self::ALPHA_NUMERIC, $dataLength = 62)
{
$this->setData($data);
$this->setDataLength($dataLength);
}
/**
* set data type
*
* @param $value
* @access public
*/
public function setData($value)
{
$this->data = $value;
}
/**
* Get data
*
* @return $data
*/
public function getData()
{
return $this->data;
}
/**
* Set data length
*
* @param $value length of string to return
* @access public
*/
public function setDataLength($value)
{
$this->dataLength = $value;
}
/**
* Get data length
*
* @access public
* @return $dataLength
*/
public function getDataLength()
{
return $this->dataLength;
}
public function __toString()
{
return substr($this->getData(), 0, $this->getDataLength());
}
}
class AssertionTuple
{
protected $assertionMethod = '';
protected $data;
public function __construct($assertionMethod, DataSetValue $data)
{
$this->setAssertionMethod($assertionMethod);
$this->setData($data);
}
/**
* Set assertion method
*
* @param $assertionMethod
* @access public
*/
public function setAssertionMethod($method)
{
$this->assertionMethod = 'assert' . ucfirst($method);
}
/**
* Get assertion method
*
* @access public
* @return $assertionMethod
*/
public function getAssertionMethod()
{
return $this->assertionMethod;
}
/**
* Set data
*
* @param $value
* @access public
*/
public function setData($value)
{
$this->data = $value;
}
public function getData()
{
return $this->data;
}
}
class AssertionStack
implements Iterator
{
private $position = 0;
protected $stack = array();
public function push(AssertionTuple $tuple)
{
$this->stack[] = $tuple;
}
public function rewind()
{
$this->position = 0;
}
public function current()
{
return $this->stack[$this->position]->getData();
}
public function key()
{
return $this->stack[$this->position]->getAssertionMethod();
}
public function next()
{
++$this->position;
}
public function valid()
{
return isset($this->stack[$this->position]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment