diff --git a/CHANGELOG-1.x.md b/CHANGELOG-1.x.md index f4ff8a0..0d42b93 100644 --- a/CHANGELOG-1.x.md +++ b/CHANGELOG-1.x.md @@ -2,6 +2,16 @@ This changelog references the relevant changes done in 1.x versions. +## v1.1.0 +* Marked these classes as deprecated as they will be removed in 2.x. + * BigNumber + * GeoPoint + * Microtime + * Identifiers\* +* Moved `ext-bcmath`, `moontoast/math`, `ramsey/uuid` in `composer.json` to __require-dev__. + If you're not on `gdbots/pbj-php` 1.1.x or later you'll need to require these in your own project. + + ## v1.0.1 * Remove __final__ from classes in anticipation of moving to "WellKnown" types in `gdbots/pbj` library. * BigNumber diff --git a/composer.json b/composer.json index 819498b..93db60e 100755 --- a/composer.json +++ b/composer.json @@ -4,13 +4,13 @@ "type": "library", "license": "Apache-2.0", "require": { - "php": ">=5.6", - "ext-bcmath": "*", - "moontoast/math": "~1.1", - "ramsey/uuid": "~3.1" + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "~4.3" + "phpunit/phpunit": "~4.3", + "ext-bcmath": "*", + "moontoast/math": "~1.1", + "ramsey/uuid": "~3.5" }, "autoload": { "psr-4": { @@ -24,7 +24,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } } } diff --git a/src/Common/BigNumber.php b/src/Common/BigNumber.php index 1c51ae0..7111946 100644 --- a/src/Common/BigNumber.php +++ b/src/Common/BigNumber.php @@ -2,8 +2,23 @@ namespace Gdbots\Common; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\BigNumber" from "gdbots/pbj" 1.1.x or later instead. + */ class BigNumber extends \Moontoast\Math\BigNumber implements \JsonSerializable { + /** + * BigNumber constructor. + * + * @param mixed $number + * @param null $scale + */ + public function __construct($number, $scale = null) + { + @trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\BigNumber" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED); + parent::__construct($number, $scale); + } + /** * @return string */ diff --git a/src/Common/GeoPoint.php b/src/Common/GeoPoint.php index 2a56619..40bf7ea 100755 --- a/src/Common/GeoPoint.php +++ b/src/Common/GeoPoint.php @@ -5,6 +5,8 @@ /** * Represents a GeoJson Point value. * @link http://geojson.org/geojson-spec.html#point + * + * @deprecated Use "Gdbots\Pbj\WellKnown\GeoPoint" from "gdbots/pbj" 1.1.x or later instead. */ class GeoPoint implements FromArray, ToArray, \JsonSerializable { @@ -22,6 +24,8 @@ class GeoPoint implements FromArray, ToArray, \JsonSerializable */ public function __construct($lat, $lon) { + @trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\GeoPoint" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED); + $this->latitude = (float) $lat; $this->longitude = (float) $lon; diff --git a/src/Common/Microtime.php b/src/Common/Microtime.php index f583ba7..a0fcf93 100644 --- a/src/Common/Microtime.php +++ b/src/Common/Microtime.php @@ -10,6 +10,8 @@ * 10 digits (unix timestamp) concatenated with 6 microsecond digits. * * @link http://php.net/manual/en/function.microtime.php + * + * @deprecated Use "Gdbots\Pbj\WellKnown\Microtime" from "gdbots/pbj" 1.1.x or later instead. */ class Microtime implements \JsonSerializable { @@ -29,7 +31,10 @@ class Microtime implements \JsonSerializable /** * Private constructor to ensure static methods are used. */ - private function __construct() {} + private function __construct() + { + @trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\Microtime" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED); + } /** * Create a new object using the current microtime. diff --git a/src/Identifiers/DatedSlugIdentifier.php b/src/Identifiers/DatedSlugIdentifier.php index 095bb65..ae9ac54 100644 --- a/src/Identifiers/DatedSlugIdentifier.php +++ b/src/Identifiers/DatedSlugIdentifier.php @@ -5,6 +5,9 @@ use Gdbots\Common\Util\SlugUtils; use Gdbots\Common\Util\StringUtils; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\DatedSlugIdentifier" from "gdbots/pbj" 1.1.x or later instead. + */ abstract class DatedSlugIdentifier implements Identifier, \JsonSerializable { /** @var string */ @@ -16,6 +19,8 @@ abstract class DatedSlugIdentifier implements Identifier, \JsonSerializable */ protected function __construct($slug) { + @trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\DatedSlugIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED); + if (!is_string($slug)) { throw new \InvalidArgumentException( sprintf('String expected but got [%s].', StringUtils::varToString($slug)) diff --git a/src/Identifiers/GeneratesIdentifier.php b/src/Identifiers/GeneratesIdentifier.php index a5510ae..4a41151 100644 --- a/src/Identifiers/GeneratesIdentifier.php +++ b/src/Identifiers/GeneratesIdentifier.php @@ -2,6 +2,9 @@ namespace Gdbots\Identifiers; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\GeneratesIdentifier" from "gdbots/pbj" 1.1.x or later instead. + */ interface GeneratesIdentifier { /** diff --git a/src/Identifiers/Identifier.php b/src/Identifiers/Identifier.php index 2c82d85..58bad43 100644 --- a/src/Identifiers/Identifier.php +++ b/src/Identifiers/Identifier.php @@ -2,6 +2,9 @@ namespace Gdbots\Identifiers; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\Identifier" from "gdbots/pbj" 1.1.x or later instead. + */ interface Identifier { /** diff --git a/src/Identifiers/SlugIdentifier.php b/src/Identifiers/SlugIdentifier.php index df9a867..0d7a6ce 100644 --- a/src/Identifiers/SlugIdentifier.php +++ b/src/Identifiers/SlugIdentifier.php @@ -5,6 +5,9 @@ use Gdbots\Common\Util\SlugUtils; use Gdbots\Common\Util\StringUtils; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\SlugIdentifier" from "gdbots/pbj" 1.1.x or later instead. + */ abstract class SlugIdentifier implements Identifier, \JsonSerializable { /** @var string */ @@ -16,6 +19,8 @@ abstract class SlugIdentifier implements Identifier, \JsonSerializable */ protected function __construct($slug) { + @trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\SlugIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED); + if (!is_string($slug)) { throw new \InvalidArgumentException( sprintf('String expected but got [%s].', StringUtils::varToString($slug)) diff --git a/src/Identifiers/StringIdentifier.php b/src/Identifiers/StringIdentifier.php index 87156ec..9a0acf2 100644 --- a/src/Identifiers/StringIdentifier.php +++ b/src/Identifiers/StringIdentifier.php @@ -4,6 +4,9 @@ use Gdbots\Common\Util\StringUtils; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\StringIdentifier" from "gdbots/pbj" 1.1.x or later instead. + */ abstract class StringIdentifier implements Identifier, \JsonSerializable { /** @var string */ @@ -15,6 +18,8 @@ abstract class StringIdentifier implements Identifier, \JsonSerializable */ protected function __construct($string) { + @trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\StringIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED); + if (!is_string($string)) { throw new \InvalidArgumentException( sprintf('String expected but got [%s].', StringUtils::varToString($string)) diff --git a/src/Identifiers/TimeUuidIdentifier.php b/src/Identifiers/TimeUuidIdentifier.php index 616c156..8188800 100644 --- a/src/Identifiers/TimeUuidIdentifier.php +++ b/src/Identifiers/TimeUuidIdentifier.php @@ -5,6 +5,9 @@ use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\TimeUuidIdentifier" from "gdbots/pbj" 1.1.x or later instead. + */ class TimeUuidIdentifier extends UuidIdentifier { /** diff --git a/src/Identifiers/UuidIdentifier.php b/src/Identifiers/UuidIdentifier.php index 082fb46..426d21b 100644 --- a/src/Identifiers/UuidIdentifier.php +++ b/src/Identifiers/UuidIdentifier.php @@ -5,6 +5,9 @@ use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; +/** + * @deprecated Use "Gdbots\Pbj\WellKnown\UuidIdentifier" from "gdbots/pbj" 1.1.x or later instead. + */ class UuidIdentifier implements Identifier, GeneratesIdentifier, \JsonSerializable { /** @var UuidInterface */ @@ -15,6 +18,7 @@ class UuidIdentifier implements Identifier, GeneratesIdentifier, \JsonSerializab */ protected function __construct(UuidInterface $uuid) { + @trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\[Time]UuidIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED); $this->uuid = $uuid; } diff --git a/tests/Common/MicrotimeTest.php b/tests/Common/MicrotimeTest.php deleted file mode 100644 index 5ff8a88..0000000 --- a/tests/Common/MicrotimeTest.php +++ /dev/null @@ -1,116 +0,0 @@ -testCount; - do { - $tod = gettimeofday(); - $sec = $tod['sec']; - $usec = $tod['usec']; - $str = $sec . str_pad($tod['usec'], 6, '0', STR_PAD_LEFT); - $m = Microtime::fromTimeOfDay($tod); - - $this->assertSame($sec, $m->getSeconds()); - $this->assertSame($sec, (int) $m->toDateTime()->format('U')); - $this->assertSame($usec, $m->getMicroSeconds()); - $this->assertSame($str, $m->toString()); - --$i; - } while ($i > 0); - } - - public function testFromString() - { - $i = $this->testCount; - do { - $tod = gettimeofday(); - $sec = $tod['sec']; - $usec = $tod['usec']; - $str = $sec . str_pad($tod['usec'], 6, '0', STR_PAD_LEFT); - $m = Microtime::fromString($str); - - $this->assertSame($sec, $m->getSeconds()); - $this->assertSame($sec, (int) $m->toDateTime()->format('U')); - $this->assertSame($usec, $m->getMicroSeconds()); - $this->assertSame($str, $m->toString()); - --$i; - } while ($i > 0); - } - - /** - * verifies that the microsecond precision is properly padded with - * zeroes when a full 6 digits are not provided. padding is done on - * the right side. e.g. 123 becomes 123000, - */ - public function testFromStringPrecision() - { - $sec = time(); - $i = 6; - do { - $usec = str_repeat('1', $i); - $usecFixed = (int) str_pad($usec, 6, '0'); - $str = $sec . $usecFixed; - $m = Microtime::fromString($sec . $usec); - $this->assertSame($sec, $m->getSeconds()); - $this->assertSame($sec, (int) $m->toDateTime()->format('U')); - $this->assertSame($usecFixed, $m->getMicroSeconds()); - $this->assertSame($str, $m->toString()); - --$i; - } while ($i > 2); - } - - public function testToDateTime() - { - $microtime = microtime(true); - list($sec, $usec) = explode('.', $microtime); - $usec = str_pad($usec, 6, '0'); - $date = \DateTime::createFromFormat('U.u', $sec . '.' . $usec); - $m = Microtime::fromString($sec . $usec); - $this->assertSame($date->format('Y-m-d H:i:s.u'), $m->toDateTime()->format('Y-m-d H:i:s.u')); - $this->assertSame( - Microtime::fromDateTime($date)->toDateTime()->format('Y-m-d H:i:s.u'), - $m->toDateTime()->format('Y-m-d H:i:s.u') - ); - } - - public function testDateTimeComparison() - { - $microtime = microtime(true); - list($sec, $usec) = explode('.', $microtime); - $usec = str_pad($usec, 6, '0'); - $date = \DateTime::createFromFormat('U.u', $sec . '.' . $usec); - $m = Microtime::fromString($sec . $usec); - $this->assertSame($date->format('Y-m-d H:i:s.u'), $m->toDateTime()->format('Y-m-d H:i:s.u')); - $this->assertEquals($date, $m->toDateTime()); - $this->assertEquals($m->toDateTime()->getOffset(), (new \DateTime('UTC'))->getOffset()); - } - - /** - * Funky test as float values get rounded when you clip digits and recreate - * them so what we're doing is verifying the float that is regenerated - * from the object results in the same 16 digit integer. - */ - public function testToFloat() - { - $i = $this->testCount; - do { - $microtime = microtime(true); - $m = Microtime::fromFloat($microtime); - $f1 = substr(str_pad(str_replace('.', '', $microtime), 16, '0'), 0, 16); - $f2 = substr(str_pad(str_replace('.', '', $m->toFloat()), 16, '0'), 0, 16); - $this->assertSame($f1, $f2); - --$i; - } while ($i > 0); - } -} diff --git a/tests/Identifiers/DatedSlugIdentifierTest.php b/tests/Identifiers/DatedSlugIdentifierTest.php deleted file mode 100644 index ac8cc34..0000000 --- a/tests/Identifiers/DatedSlugIdentifierTest.php +++ /dev/null @@ -1,48 +0,0 @@ -format('Y/m/d'); - - $expected = [ - "$datePart/homer-simpson" => 'Homer Simpson!', - "$datePart/marge-simpson" => '--Marge __ Simpson!--', - "2012/12/12/bart-simpson" => '-/2012/12/12/--Bart __ Simpson!--/', - ]; - foreach ($expected as $k => $v) { - $this->assertSame($k, SampleDatedSlugIdentifier::create($v)->toString()); - } - } - - public function testFromString() - { - $expected = '2012/12/12/valid-slug'; - $slug = SampleDatedSlugIdentifier::fromString($expected); - $this->assertSame($expected, $slug->toString()); - } - - public function testEquals() - { - $expected = '2012/12/12/valid-slug'; - $slug = SampleDatedSlugIdentifier::fromString($expected); - $slug2 = SampleDatedSlugIdentifier::fromString($slug->toString()); - $this->assertTrue($slug->equals($slug2)); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testFromStringInvalid() - { - $slug = SampleDatedSlugIdentifier::fromString('invalid-slug'); - } -} diff --git a/tests/Identifiers/SlugIdentifierTest.php b/tests/Identifiers/SlugIdentifierTest.php deleted file mode 100644 index 348820f..0000000 --- a/tests/Identifiers/SlugIdentifierTest.php +++ /dev/null @@ -1,44 +0,0 @@ - 'Homer Simpson!', - 'marge-simpson' => '--Marge __ Simpson!--', - ]; - foreach ($expected as $k => $v) { - $this->assertSame($k, SampleSlugIdentifier::create($v)->toString()); - } - } - - public function testFromString() - { - $expected = 'valid-slug'; - $slug = SampleSlugIdentifier::fromString($expected); - $this->assertSame($expected, $slug->toString()); - } - - public function testEquals() - { - $expected = 'valid-slug'; - $slug = SampleSlugIdentifier::fromString($expected); - $slug2 = SampleSlugIdentifier::fromString($slug->toString()); - $this->assertTrue($slug->equals($slug2)); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testFromStringInvalid() - { - $slug = SampleSlugIdentifier::fromString('!invalid Slug'); - } -} diff --git a/tests/Identifiers/TimeUuidIdentifierTest.php b/tests/Identifiers/TimeUuidIdentifierTest.php deleted file mode 100644 index e4d5a2b..0000000 --- a/tests/Identifiers/TimeUuidIdentifierTest.php +++ /dev/null @@ -1,33 +0,0 @@ -assertTrue(Uuid::isValid($id)); - - $uuid = Uuid::fromString($id->toString()); - $this->assertTrue($uuid->getVersion() == 1); - } - - public function testFromString() - { - $id = TimeUuidIdentifier::fromString(Uuid::NAMESPACE_DNS); - $this->assertSame($id->toString(), Uuid::NAMESPACE_DNS); - } - - public function testEquals() - { - $id = TimeUuidIdentifier::fromString(Uuid::NAMESPACE_DNS); - $id2 = TimeUuidIdentifier::fromString(Uuid::NAMESPACE_DNS); - $id3 = TimeUuidIdentifier::fromString(Uuid::NAMESPACE_OID); - $this->assertTrue($id->equals($id2)); - $this->assertFalse($id->equals($id3)); - } -} diff --git a/tests/Identifiers/UuidIdentifierTest.php b/tests/Identifiers/UuidIdentifierTest.php deleted file mode 100644 index b771f69..0000000 --- a/tests/Identifiers/UuidIdentifierTest.php +++ /dev/null @@ -1,33 +0,0 @@ -assertTrue(Uuid::isValid($id)); - - $uuid = Uuid::fromString($id->toString()); - $this->assertTrue($uuid->getVersion() == 4); - } - - public function testFromString() - { - $id = UuidIdentifier::fromString(Uuid::NAMESPACE_DNS); - $this->assertSame($id->toString(), Uuid::NAMESPACE_DNS); - } - - public function testEquals() - { - $id = UuidIdentifier::fromString(Uuid::NAMESPACE_DNS); - $id2 = UuidIdentifier::fromString(Uuid::NAMESPACE_DNS); - $id3 = UuidIdentifier::fromString(Uuid::NAMESPACE_OID); - $this->assertTrue($id->equals($id2)); - $this->assertFalse($id->equals($id3)); - } -}