diff --git a/composer.json b/composer.json index 11fcf45..5417248 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "Swow\\": "src/" }, "files": [ - "src/functions.php", + "src/bootstrap.php", "src/Debug/functions.php" ] }, diff --git a/src/Library.php b/src/Library.php new file mode 100644 index 0000000..4c67fb1 --- /dev/null +++ b/src/Library.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, + * please view the LICENSE file that was distributed with this source code + */ + +declare(strict_types=1); + +namespace Swow; + +final class Library +{ + public const VERSION = '0.2.0-alpha'; + public const VERSION_ID = 200; + public const MAJOR_VERSION = 0; + public const MINOR_VERSION = 2; + public const RELEASE_VERSION = 0; + public const EXTRA_VERSION = 'alpha'; + + public const REQUIRED_EXTENSION_VERSION = '^0.2.0'; +} diff --git a/src/bootstrap.php b/src/bootstrap.php new file mode 100644 index 0000000..50d129a --- /dev/null +++ b/src/bootstrap.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, + * please view the LICENSE file that was distributed with this source code + */ + +declare(strict_types=1); + +use Composer\Semver\Semver; +use Swow\Extension; +use Swow\Library; + +if (!class_exists(Extension::class)) { + return; +} + +if (!Semver::satisfies(Extension::VERSION, Library::REQUIRED_EXTENSION_VERSION)) { + throw new Error(sprintf( + '%s extension version mismatch, required: %s, actual: %s', + Swow::class, Library::REQUIRED_EXTENSION_VERSION, Extension::VERSION + )); +} diff --git a/src/functions.php b/src/functions.php deleted file mode 100644 index 8a4bf30..0000000 --- a/src/functions.php +++ /dev/null @@ -1,14 +0,0 @@ - - * - * For the full copyright and license information, - * please view the LICENSE file that was distributed with this source code - */ - -declare(strict_types=1); - -define('SWOW_LIBRARY', true); diff --git a/tests/SwowTest.php b/tests/SwowTest.php index 424919a..63996dd 100644 --- a/tests/SwowTest.php +++ b/tests/SwowTest.php @@ -14,9 +14,10 @@ namespace Swow\Tests; use PHPUnit\Framework\TestCase; +use Swow; -use function defined; use function extension_loaded; +use function strlen; /** * @internal @@ -26,12 +27,25 @@ final class SwowTest extends TestCase { public function testSwowExtension(): void { - $this->assertTrue(extension_loaded('swow')); + $this->assertTrue(extension_loaded(Swow::class)); + $this->assertGreaterThan(0, Swow\Extension::VERSION_ID); } public function testSwowLibrary(): void { - $this->assertTrue(defined('SWOW_LIBRARY')); - $this->assertTrue(SWOW_LIBRARY); + $this->assertTrue(Swow::isLibraryLoaded()); + $this->assertSame(Swow\Library::VERSION, sprintf( + '%d.%d.%d%s%s', + Swow\Library::MAJOR_VERSION, + Swow\Library::MINOR_VERSION, + Swow\Library::RELEASE_VERSION, + strlen(Swow\Library::EXTRA_VERSION) > 0 ? '-' : '', Swow\Library::EXTRA_VERSION + )); + $this->assertSame(Swow\Library::VERSION_ID, (int) sprintf( + '%02d%02d%02d', + Swow\Library::MAJOR_VERSION, + Swow\Library::MINOR_VERSION, + Swow\Library::RELEASE_VERSION + )); } }