],
"extra": {
"branch-alias": {
- "dev-master": "0.1-dev"
+ "dev-master": "0.2-dev"
}
}
}
--- /dev/null
+<?php
+
+namespace PFF;
+
+final class Arr
+{
+ public static function get($array, $key, $default=null)
+ {
+ if (array_key_exists($key, $array))
+ return $array[$key];
+ else
+ return $default;
+ }
+
+ public static function ensureKeyExists(&$array, $key, $default=null)
+ {
+ if (!array_key_exists($key, $array))
+ return $array[$key] = $default;
+ }
+
+ public static function pushToKey(&$array, $key, $value)
+ {
+ if (array_key_exists($key, $array))
+ return $array[$key][] = $value;
+ else
+ return $array[$key] = array($value);
+ }
+
+ public static function pop(&$array, $key, $default=null)
+ {
+ if (array_key_exists($key, $array)) {
+ $value = $array[$key];
+ unset($array[$key]);
+ return $value;
+ } else {
+ return $default;
+ }
+ }
+
+ public static function flatten($array)
+ {
+ $result = array();
+ array_walk_recursive($array, function ($value) use (&$result) {
+ $result[] = $value;
+ });
+ return $result;
+ }
+}
+
+++ /dev/null
-<?php
-
-final class ArrayTools
-{
- public static function get($array, $key, $default=null)
- {
- if (array_key_exists($key, $array))
- return $array[$key];
- else
- return $default;
- }
-
- public static function ensureKeyExists(&$array, $key, $default=null)
- {
- if (!array_key_exists($key, $array))
- return $array[$key] = $default;
- }
-
- public static function pushToKey(&$array, $key, $value)
- {
- if (array_key_exists($key, $array))
- return $array[$key][] = $value;
- else
- return $array[$key] = array($value);
- }
-
- public static function pop(&$array, $key, $default=null)
- {
- if (array_key_exists($key, $array)) {
- $value = $array[$key];
- unset($array[$key]);
- return $value;
- } else {
- return $default;
- }
- }
-}
-
--- /dev/null
+<?php
+
+namespace PFF;
+
+final class Collection
+{
+ /*
+ * Example output:
+ * 1 4 7 9
+ * 2 5 8 10
+ * 3 6
+ */
+ public static function columns($collection, $columnsCount)
+ {
+ $count = count($collection);
+ $r = $count % $columnsCount;
+ $length = ($count - $r) / $columnsCount;
+
+ $columnLengths = array();
+ for ($i = 0; $i < $columnsCount; ++$i) {
+ $columnLengths[] = $length + ($i < $r ? 1 : 0);
+ }
+
+ $column = array();
+ $columnIndex = 0;
+ foreach ($collection as $item) {
+ if (count($column) >= $columnLengths[$columnIndex]) {
+ $columns[] = $column;
+ $column = array();
+ $columnIndex++;
+ }
+ $column[] = $item;
+ }
+ $columns[] = $column;
+ return $columns;
+ }
+
+ public static function chunks($collection, $size, $pad=false)
+ {
+ $result = array();
+ $chunk = array();
+ foreach ($collection as $item) {
+ $chunk[] = $item;
+ if (count($chunk) === $size) {
+ $result[] = $chunk;
+ $chunk = array();
+ }
+ }
+ $c = count($chunk);
+ if ($c != 0) {
+ if ($pad) {
+ while ($c < $size) {
+ $chunk[] = null;
+ ++$c;
+ }
+ }
+ $result[] = $chunk;
+ }
+ return $result;
+ }
+}
+
+++ /dev/null
-<?php
-
-final class Collections
-{
- /*
- * Example output:
- * 1 4 7 9
- * 2 5 8 10
- * 3 6
- */
- public static function columns($collection, $columnsCount)
- {
- $count = count($collection);
- $r = $count % $columnsCount;
- $length = ($count - $r) / $columnsCount;
-
- $columnLengths = array();
- for ($i = 0; $i < $columnsCount; ++$i) {
- $columnLengths[] = $length + ($i < $r ? 1 : 0);
- }
-
- $column = array();
- $columnIndex = 0;
- foreach ($collection as $item) {
- if (count($column) >= $columnLengths[$columnIndex]) {
- $columns[] = $column;
- $column = array();
- $columnIndex++;
- }
- $column[] = $item;
- }
- $columns[] = $column;
- return $columns;
- }
-
- public static function chunks($collection, $size, $pad=false)
- {
- $result = array();
- $chunk = array();
- foreach ($collection as $item) {
- $chunk[] = $item;
- if (count($chunk) === $size) {
- $result[] = $chunk;
- $chunk = array();
- }
- }
- $c = count($chunk);
- if ($c != 0) {
- if ($pad) {
- while ($c < $size) {
- $chunk[] = null;
- ++$c;
- }
- }
- $result[] = $chunk;
- }
- return $result;
- }
-}
-
<?php
+namespace PFF;
+
+use \Pegp as Pegp;
+
final class DateFormat
{
const DATE_BIG_ENDIAN = 0;
<?php
-namespace HtmlBuilder;
+namespace PFF\HtmlBuilder;
class Tag
{
<?php
+namespace PFF;
+
class Mixins
{
private $methods = array();
<?php
+namespace PFF;
+
class Regexp
{
public static function email()
--- /dev/null
+<?php
+
+namespace PFF;
+
+final class Str
+{
+ public static function startsWith($haystack, $needle)
+ {
+ return !strncmp($haystack, $needle, strlen($needle));
+ }
+
+ public static function endsWith($haystack, $needle)
+ {
+ $length = strlen($needle);
+ return !$length || substr($haystack, -$length) === $needle;
+ }
+}
+
+++ /dev/null
-<?php
-
-final class StringTools
-{
- public static function startsWith($haystack, $needle)
- {
- return !strncmp($haystack, $needle, strlen($needle));
- }
-
- public static function endsWith($haystack, $needle)
- {
- $length = strlen($needle);
- return !$length || substr($haystack, -$length) === $needle;
- }
-}
-
--- /dev/null
+<?php
+
+class ArrTest extends PHPUnit_Framework_TestCase
+{
+ public function testGet()
+ {
+ $arr = array(
+ 'apple' => 100,
+ 'grapefruit' => 400,
+ 'carrot' => 50,
+ );
+
+ $this->assertEquals(400, \PFF\Arr::get($arr, 'grapefruit'));
+ $this->assertEquals(null, \PFF\Arr::get($arr, 'orange'));
+ $this->assertEquals('no-oranges', \PFF\Arr::get($arr, 'orange', 'no-oranges'));
+ }
+
+ public function testEnsureKeyExists()
+ {
+ $arr = array(
+ 'apple' => 100,
+ 'grapefruit' => 400,
+ 'carrot' => 50,
+ );
+
+ $this->assertEquals(false, array_key_exists('orange', $arr));
+ \PFF\Arr::ensureKeyExists($arr, 'orange');
+ $this->assertEquals(true, array_key_exists('orange', $arr));
+ }
+
+ public function testPushToKey()
+ {
+ $arr = array('carrot' => array('orange'));
+
+ \PFF\Arr::pushToKey($arr, 'apple', 'green');
+ \PFF\Arr::pushToKey($arr, 'carrot', 'long');
+ \PFF\Arr::pushToKey($arr, 'apple', 'sweet');
+
+ $this->assertEquals(array('green', 'sweet'), $arr['apple']);
+ $this->assertEquals(array('orange', 'long'), $arr['carrot']);
+ }
+
+ public function testPop()
+ {
+ $arr = array(
+ 'apple' => 100,
+ 'grapefruit' => 400,
+ 'carrot' => 50,
+ );
+
+ $apple = \PFF\Arr::pop($arr, 'apple');
+ $this->assertEquals(false, array_key_exists('apple', $arr));
+ $this->assertEquals(100, $apple);
+
+ $apple = \PFF\Arr::pop($arr, 'apple');
+ $this->assertEquals(null, $apple);
+
+ $apple = \PFF\Arr::pop($arr, 'apple', 'what?');
+ $this->assertEquals('what?', $apple);
+ }
+
+ public function testFlatten()
+ {
+ $arr = array('a', 'b', array(array(array('x'), 'y', 'z')), array(array('p')));
+ $flat = \PFF\Arr::flatten($arr);
+ $this->assertEquals(array('a', 'b', 'x', 'y', 'z', 'p'), $flat);
+ }
+}
+
+++ /dev/null
-<?php
-
-class ArrayToolsTest extends PHPUnit_Framework_TestCase
-{
- public function testGet()
- {
- $arr = array(
- 'apple' => 100,
- 'grapefruit' => 400,
- 'carrot' => 50,
- );
-
- $this->assertEquals(400, ArrayTools::get($arr, 'grapefruit'));
- $this->assertEquals(null, ArrayTools::get($arr, 'orange'));
- $this->assertEquals('no-oranges', ArrayTools::get($arr, 'orange', 'no-oranges'));
- }
-
- public function testEnsureKeyExists()
- {
- $arr = array(
- 'apple' => 100,
- 'grapefruit' => 400,
- 'carrot' => 50,
- );
-
- $this->assertEquals(false, array_key_exists('orange', $arr));
- ArrayTools::ensureKeyExists($arr, 'orange');
- $this->assertEquals(true, array_key_exists('orange', $arr));
- }
-
- public function testPushToKey()
- {
- $arr = array('carrot' => array('orange'));
-
- ArrayTools::pushToKey($arr, 'apple', 'green');
- ArrayTools::pushToKey($arr, 'carrot', 'long');
- ArrayTools::pushToKey($arr, 'apple', 'sweet');
-
- $this->assertEquals(array('green', 'sweet'), $arr['apple']);
- $this->assertEquals(array('orange', 'long'), $arr['carrot']);
- }
-
- public function testPop()
- {
- $arr = array(
- 'apple' => 100,
- 'grapefruit' => 400,
- 'carrot' => 50,
- );
-
- $apple = ArrayTools::pop($arr, 'apple');
- $this->assertEquals(false, array_key_exists('apple', $arr));
- $this->assertEquals(100, $apple);
-
- $apple = ArrayTools::pop($arr, 'apple');
- $this->assertEquals(null, $apple);
-
- $apple = ArrayTools::pop($arr, 'apple', 'what?');
- $this->assertEquals('what?', $apple);
- }
-}
-
<?php
-class CollectionsTest extends PHPUnit_Framework_TestCase
+class CollectionTest extends PHPUnit_Framework_TestCase
{
public function testColumns()
{
'carrot',
'tomato',
);
- $columns = Collections::columns($arr, 3);
+ $columns = \PFF\Collection::columns($arr, 3);
$this->assertEquals(3, count($columns));
$this->assertEquals(2, count($columns[0]));
$this->assertEquals(1, count($columns[1]));
'carrot',
'tomato',
);
- $chunks = Collections::chunks($arr, 3);
+ $chunks = \PFF\Collection::chunks($arr, 3);
$this->assertEquals(2, count($chunks));
$this->assertEquals(3, count($chunks[0]));
$this->assertEquals(1, count($chunks[1]));
'carrot',
'tomato',
);
- $chunks = Collections::chunks($arr, 3, true);
+ $chunks = \PFF\Collection::chunks($arr, 3, true);
$this->assertEquals(2, count($chunks));
$this->assertEquals(3, count($chunks[0]));
$this->assertEquals(3, count($chunks[1]));
<?php
-class Format_Test extends PHPUnit_Framework_TestCase
+class FormatTest extends PHPUnit_Framework_TestCase
{
public function testFlags()
{
- $this->assertEquals(DateFormat::DATE_DEFAULT, DateFormat::DATE_BIG_ENDIAN | DateFormat::DATE_HYPHENS);
- $this->assertEquals(DateFormat::DATE_US, DateFormat::DATE_MIDDLE_ENDIAN | DateFormat::DATE_SLASHES);
- $this->assertEquals(DateFormat::DATE_EUROPEAN, DateFormat::DATE_LITTLE_ENDIAN | DateFormat::DATE_DOTS);
+ $this->assertEquals(\PFF\DateFormat::DATE_DEFAULT, \PFF\DateFormat::DATE_BIG_ENDIAN | \PFF\DateFormat::DATE_HYPHENS);
+ $this->assertEquals(\PFF\DateFormat::DATE_US, \PFF\DateFormat::DATE_MIDDLE_ENDIAN | \PFF\DateFormat::DATE_SLASHES);
+ $this->assertEquals(\PFF\DateFormat::DATE_EUROPEAN, \PFF\DateFormat::DATE_LITTLE_ENDIAN | \PFF\DateFormat::DATE_DOTS);
}
public function testDateFlagsFromString()
{
- $this->assertEquals(DateFormat::DATE_DEFAULT, DateFormat::dateFlagsFromString('Default'));
- $this->assertEquals(DateFormat::DATE_DEFAULT, DateFormat::dateFlagsFromString('Big-endian hyphEns'));
- $this->assertEquals(DateFormat::DATE_EUROPEAN, DateFormat::dateFlagsFromString('European'));
- $this->assertEquals(DateFormat::DATE_EUROPEAN, DateFormat::dateFlagsFromString('little-endian dots'));
- $this->assertEquals(DateFormat::DATE_US, DateFormat::dateFlagsFromString('US'));
- $this->assertEquals(DateFormat::DATE_US, DateFormat::dateFlagsFromString('Middle-Endian Slashes'));
- $this->assertEquals(DateFormat::DATE_BIG_ENDIAN | DateFormat::DATE_SPACES,
- DateFormat::dateFlagsFromString('big-endian spaces'));
+ $this->assertEquals(\PFF\DateFormat::DATE_DEFAULT, \PFF\DateFormat::dateFlagsFromString('Default'));
+ $this->assertEquals(\PFF\DateFormat::DATE_DEFAULT, \PFF\DateFormat::dateFlagsFromString('Big-endian hyphEns'));
+ $this->assertEquals(\PFF\DateFormat::DATE_EUROPEAN, \PFF\DateFormat::dateFlagsFromString('European'));
+ $this->assertEquals(\PFF\DateFormat::DATE_EUROPEAN, \PFF\DateFormat::dateFlagsFromString('little-endian dots'));
+ $this->assertEquals(\PFF\DateFormat::DATE_US, \PFF\DateFormat::dateFlagsFromString('US'));
+ $this->assertEquals(\PFF\DateFormat::DATE_US, \PFF\DateFormat::dateFlagsFromString('Middle-Endian Slashes'));
+ $this->assertEquals(\PFF\DateFormat::DATE_BIG_ENDIAN | \PFF\DateFormat::DATE_SPACES,
+ \PFF\DateFormat::dateFlagsFromString('big-endian spaces'));
}
public function testDatetimeFlagsFromString()
{
- $this->assertEquals(DateFormat::DATETIME_DEFAULT, DateFormat::datetimeFlagsFromString('Default'));
- $this->assertEquals(DateFormat::DATETIME_DEFAULT, DateFormat::datetimeFlagsFromString('Big-endian hyphEns 24'));
- $this->assertEquals(DateFormat::DATETIME_EUROPEAN, DateFormat::datetimeFlagsFromString('European'));
- $this->assertEquals(DateFormat::DATETIME_EUROPEAN, DateFormat::datetimeFlagsFromString('little-endian dots 24'));
- $this->assertEquals(DateFormat::DATETIME_US, DateFormat::datetimeFlagsFromString('US'));
- $this->assertEquals(DateFormat::DATETIME_US, DateFormat::datetimeFlagsFromString('Middle-Endian Slashes 12-upper'));
- $this->assertEquals(DateFormat::DATE_BIG_ENDIAN | DateFormat::DATE_SPACES | DateFormat::TIME_12HOURS_LOWER | DateFormat::TIME_SECONDS,
- DateFormat::datetimeFlagsFromString("big-endian spaces \n 12-lower Seconds"));
+ $this->assertEquals(\PFF\DateFormat::DATETIME_DEFAULT, \PFF\DateFormat::datetimeFlagsFromString('Default'));
+ $this->assertEquals(\PFF\DateFormat::DATETIME_DEFAULT, \PFF\DateFormat::datetimeFlagsFromString('Big-endian hyphEns 24'));
+ $this->assertEquals(\PFF\DateFormat::DATETIME_EUROPEAN, \PFF\DateFormat::datetimeFlagsFromString('European'));
+ $this->assertEquals(\PFF\DateFormat::DATETIME_EUROPEAN, \PFF\DateFormat::datetimeFlagsFromString('little-endian dots 24'));
+ $this->assertEquals(\PFF\DateFormat::DATETIME_US, \PFF\DateFormat::datetimeFlagsFromString('US'));
+ $this->assertEquals(\PFF\DateFormat::DATETIME_US, \PFF\DateFormat::datetimeFlagsFromString('Middle-Endian Slashes 12-upper'));
+ $this->assertEquals(\PFF\DateFormat::DATE_BIG_ENDIAN | \PFF\DateFormat::DATE_SPACES | \PFF\DateFormat::TIME_12HOURS_LOWER | \PFF\DateFormat::TIME_SECONDS,
+ \PFF\DateFormat::datetimeFlagsFromString("big-endian spaces \n 12-lower Seconds"));
}
}
{
public function testTag()
{
- $tag = HtmlBuilder\Tag::div(array('class' => 'container'))
+ $tag = \PFF\HtmlBuilder\Tag::div(array('class' => 'container'))
->append('Hello, "World"')
- ->append(HtmlBuilder\Tag::a()->append('click ')->raw('<b>me</b>'));
+ ->append(\PFF\HtmlBuilder\Tag::a()->append('click ')->raw('<b>me</b>'));
$this->assertEquals('<div class="container">Hello, "World"<a>click <b>me</b></a></div>', (string)$tag);
}
<?php
-class SomeMixin extends Mixin
+class SomeMixin extends \PFF\Mixin
{
public function getSmthUseful()
{
}
}
-class WrapMixin extends Mixin
+class WrapMixin extends \PFF\Mixin
{
public function getSmthUseful()
{
}
}
-class Mixture extends Mixable
+class Mixture extends \PFF\Mixable
{
protected function __mixins() { return array('SomeMixin', 'WrapMixin'); }
--- /dev/null
+<?php
+
+class StrTest extends PHPUnit_Framework_TestCase
+{
+ public function testStartsWith()
+ {
+ $this->assertTrue(\PFF\Str::startsWith('abcdef', 'abc'));
+ $this->assertFalse(\PFF\Str::startsWith(' abcdef', 'abc'));
+ $this->assertFalse(\PFF\Str::startsWith('abc', 'abcdef'));
+ $this->assertTrue(\PFF\Str::startsWith('abc', 'abc'));
+ $this->assertTrue(\PFF\Str::startsWith('abc', ''));
+ $this->assertFalse(\PFF\Str::startsWith('abc', ' '));
+ }
+
+ public function testEndsWith()
+ {
+ $this->assertTrue(\PFF\Str::endsWith('abcdef', 'def'));
+ $this->assertFalse(\PFF\Str::endsWith('abcdef ', 'def'));
+ $this->assertFalse(\PFF\Str::endsWith('abc', 'abcdef'));
+ $this->assertTrue(\PFF\Str::endsWith('abc', 'abc'));
+ $this->assertTrue(\PFF\Str::endsWith('abc', ''));
+ $this->assertFalse(\PFF\Str::endsWith('abc', ' '));
+ }
+}
+
+++ /dev/null
-<?php
-
-class StringToolsTest extends PHPUnit_Framework_TestCase
-{
- public function testStartsWith()
- {
- $this->assertTrue(StringTools::startsWith('abcdef', 'abc'));
- $this->assertFalse(StringTools::startsWith(' abcdef', 'abc'));
- $this->assertFalse(StringTools::startsWith('abc', 'abcdef'));
- $this->assertTrue(StringTools::startsWith('abc', 'abc'));
- $this->assertTrue(StringTools::startsWith('abc', ''));
- $this->assertFalse(StringTools::startsWith('abc', ' '));
- }
-
- public function testEndsWith()
- {
- $this->assertTrue(StringTools::endsWith('abcdef', 'def'));
- $this->assertFalse(StringTools::endsWith('abcdef ', 'def'));
- $this->assertFalse(StringTools::endsWith('abc', 'abcdef'));
- $this->assertTrue(StringTools::endsWith('abc', 'abc'));
- $this->assertTrue(StringTools::endsWith('abc', ''));
- $this->assertFalse(StringTools::endsWith('abc', ' '));
- }
-}
-