From a29570a21f12bb91a162d8ecb3d39b7470c65846 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 17 Dec 2016 23:16:18 +0100 Subject: [PATCH] WIP --- src/array.php | 32 ++++++++++++++++++++++++++++++++ src/key.php | 32 ++++++++++++++++++++++++++++++++ src/str.php | 5 +++++ src/symbol.php | 15 ++++++++------- t/StrTest.php | 15 +++++++++++++++ 5 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 src/key.php diff --git a/src/array.php b/src/array.php index 7978a3e..11f188f 100644 --- a/src/array.php +++ b/src/array.php @@ -85,3 +85,35 @@ final class Arr return $result; } } + +final class Map +{ + public $data = array(); + + static function create() + { + return new self; + } + + function __set($name, $value) + { + $this->data[$name] = $value; + } + + function __get($name) + { + return $this->data[$name]; + } + + function __call($method, $args) + { + if (preg_match('/^set([A-Z]\w+)$/', $method, $m)) { + $name = \PFF\Str::underscore($m[1]); + $this->data[$name] = $args[0]; + return $this; + } else { + $name = \PFF\Str::underscore($method); + return $this->data[$name]; + } + } +} diff --git a/src/key.php b/src/key.php new file mode 100644 index 0000000..07b02c9 --- /dev/null +++ b/src/key.php @@ -0,0 +1,32 @@ +name = $name; } function __clone() @@ -28,13 +29,13 @@ final class Symbol public static function intern($name) { - if (array_key_exists($name, self::$symbols)) + if (array_key_exists($name, self::$symbols)) { return self::$symbols[$name]; - - $symbol = new self; - $symbol->name = $name; - self::$symbols[$name] = $symbol; - return $symbol; + } else { + $symbol = new self($name); + self::$symbols[$name] = $symbol; + return $symbol; + } } public static function __callStatic($name, $args) diff --git a/t/StrTest.php b/t/StrTest.php index adf76f2..6cb19ae 100644 --- a/t/StrTest.php +++ b/t/StrTest.php @@ -21,5 +21,20 @@ class StrTest extends PHPUnit_Framework_TestCase $this->assertTrue(\PFF\Str::endsWith('abc', '')); $this->assertFalse(\PFF\Str::endsWith('abc', ' ')); } + + public function testUnderscore() + { + $this->assertEquals('', \PFF\Str::underscore(null)); + $this->assertEquals('7.5', \PFF\Str::underscore(7.5)); + $this->assertEquals('', \PFF\Str::underscore('')); + $this->assertEquals('abc', \PFF\Str::underscore('abc')); + $this->assertEquals('abc', \PFF\Str::underscore('Abc')); + $this->assertEquals('a_bc', \PFF\Str::underscore('ABc')); + $this->assertEquals('a_bc', \PFF\Str::underscore('aBc')); + $this->assertEquals('camel_case', \PFF\Str::underscore('CamelCase')); + $this->assertEquals('camel_case', \PFF\Str::underscore('camelCase')); + $this->assertEquals('snake_case', \PFF\Str::underscore('snake_case')); + $this->assertEquals('snake_case', \PFF\Str::underscore('snake_Case')); + } } -- 2.49.0