From d455f4413a964da8d9073c3e5edb014b8b45b25c Mon Sep 17 00:00:00 2001 From: Luke Watts Date: Sat, 9 Mar 2024 14:56:18 +0000 Subject: [PATCH] Renaming package to slimphp-support. Updating all namespaces --- README.md | 22 +++++++++++----------- composer.json | 6 +++--- src/Contracts/Pipeline.php | 2 +- src/Facades/App.php | 5 ++--- src/Facades/Container.php | 4 ++-- src/Facades/Pipeline.php | 20 ++++++++++---------- src/Facades/Response.php | 8 ++++---- src/Facades/ResponseFactory.php | 4 ++-- src/Http/Response.php | 4 ++-- src/Support/Facade.php | 2 +- src/Support/HigherOrderTapProxy.php | 2 +- src/Support/HigherOrderWhenProxy.php | 2 +- src/Support/Hub.php | 4 ++-- src/Support/Pipeline.php | 6 +++--- src/Support/Traits/Conditionable.php | 4 ++-- src/Support/Traits/Dumpable.php | 2 +- src/Support/Traits/ForwardsCalls.php | 2 +- src/Support/Traits/Macroable.php | 19 +++++++------------ src/Support/Traits/Tappable.php | 4 ++-- src/Support/helpers.php | 4 ++-- tests/Facades/AppTest.php | 6 +++--- tests/Facades/ContainerTest.php | 8 ++++---- tests/Facades/FacadeTest.php | 4 ++-- tests/Facades/PipelineTest.php | 8 ++++---- tests/Facades/ResponseTest.php | 12 ++++++------ tests/Support/HelperFunctionsTest.php | 8 ++++---- tests/Support/HubTest.php | 4 ++-- tests/Support/PipelineTest.php | 4 ++-- tests/Support/Traits/ConditionableTest.php | 6 +++--- tests/Support/Traits/Dumpable.php | 2 +- tests/Support/Traits/ForwardsCallsTest.php | 12 ++++++------ tests/Support/Traits/MacroableTest.php | 4 ++-- tests/Support/Traits/TappableTest.php | 4 ++-- 33 files changed, 101 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index 74e2694..5f93345 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,28 @@ -# SlimPHP Facades +# SlimPHP Support Add Laravel style facades, traits and helper functions to any SlimPHP app ## Installation ```bash -composer require affinity4/slimphp-facades +composer require affinity4/slimphp-support ``` ## Usage ### Setting up Facades in your Application -To use SlimPHP Facades, you first need to create your Slim app as normal, with either `Slim\App\AppFactory` or `DI\Container\Slim\Bridge`. Then you'll need to call `SlimFacades\Support\Facade::setFacadeApplication($app)`: +To use SlimPHP Facades, you first need to create your Slim app as normal, with either `Slim\App\AppFactory` or `DI\Container\Slim\Bridge`. Then you'll need to call `Affinity4\SlimSupport\Support\Facade::setFacadeApplication($app)`: ```php use Slim\Factory\AppFactory; -use SlimFacades\Support\Facade; +use Affinity4\SlimSupport\Support\Facade; $app = AppFactory::createFromContainer(); Facade::setFacadeApplication($app); ``` -You will now have access to all SlimFacades, as well as the helper function (e.g. `response()`) +You will now have access to all Facades, as well as the helper function (e.g. `response()`) ### App Facade @@ -32,7 +32,7 @@ Facade for `Slim\App`: use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Slim\Factory\AppFactory; -use SlimFacades\Support\Facade; +use Affinity4\SlimSupport\Support\Facade; $app = AppFactory::createFromContainer(); Facade::setFacadeApplication($app); @@ -47,7 +47,7 @@ App::run(); ### Container ```php -use SlimFacades\Facades\Container; +use Affinity4\SlimSupport\Facades\Container; Container::set('some-service', function () { return SomeService(); @@ -63,7 +63,7 @@ if (Container::has('some-service')) { #### JSON Response ```php -use SlimFacades\Facades\Container; +use Affinity4\SlimSupport\Facades\Container; App::get('/', function($request) { return Response::json(['test' => 'payload'])->get(); @@ -125,7 +125,7 @@ return tap(new Psr7Response(), function ($response) { ### Tappable ```php -use SlimFacades\Support\Traits\Tappable; +use Affinity4\SlimSupport\Support\Traits\Tappable; class TappableClass { @@ -176,7 +176,7 @@ Instead you just want to call a write method directly from the `$response` insta ```php use GuzzleHttp\Psr7\Response; -use SlimFacades\Support\Traits\Macroable; +use Affinity4\SlimSupport\Support\Traits\Macroable; class MacroableResponse extends Response { @@ -187,7 +187,7 @@ class MacroableResponse extends Response Then we need to add `MacroableResponse` to our container, so we are always dealing with the same instance (not all instances will have the "macroed" methods). ```php -use SlimFacades\Facades\Container; +use Affinity4\SlimSupport\Facades\Container; // ... above code here Container::set('response', function () { diff --git a/composer.json b/composer.json index f32fb86..09d4855 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "affinity4/slimphp-facades", + "name": "affinity4/slimphp-support", "description": "Add Laravel style facades, traits and helper functions to any SlimPHP app", "type": "library", "license": "MIT", @@ -12,7 +12,7 @@ ], "autoload": { "psr-4": { - "SlimFacades\\": "src/" + "Affinity4\\SlimSupport\\": "src/" }, "files": [ "./src/Support/helpers.php" @@ -20,7 +20,7 @@ }, "autoload-dev": { "psr-4": { - "SlimFacades\\Tests\\": "tests/" + "Affinity4\\SlimSupport\\Tests\\": "tests/" } }, "require": { diff --git a/src/Contracts/Pipeline.php b/src/Contracts/Pipeline.php index 0fa1c4c..cae1c7b 100644 --- a/src/Contracts/Pipeline.php +++ b/src/Contracts/Pipeline.php @@ -1,6 +1,6 @@ getMethods( - ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED + $methods = (new \ReflectionClass($mixin))->getMethods( + \ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED ); foreach ($methods as $method) { @@ -83,14 +78,14 @@ public static function flushMacros() public static function __callStatic($method, $parameters) { if (! static::hasMacro($method)) { - throw new BadMethodCallException(sprintf( + throw new \BadMethodCallException(sprintf( 'Method %s::%s does not exist.', static::class, $method )); } $macro = static::$macros[$method]; - if ($macro instanceof Closure) { + if ($macro instanceof \Closure) { $macro = $macro->bindTo(null, static::class); } @@ -109,14 +104,14 @@ public static function __callStatic($method, $parameters) public function __call($method, $parameters) { if (! static::hasMacro($method)) { - throw new BadMethodCallException(sprintf( + throw new \BadMethodCallException(sprintf( 'Method %s::%s does not exist.', static::class, $method )); } $macro = static::$macros[$method]; - if ($macro instanceof Closure) { + if ($macro instanceof \Closure) { $macro = $macro->bindTo($this, static::class); } diff --git a/src/Support/Traits/Tappable.php b/src/Support/Traits/Tappable.php index 9731cd7..22ecaea 100644 --- a/src/Support/Traits/Tappable.php +++ b/src/Support/Traits/Tappable.php @@ -1,6 +1,6 @@ app); } - public function testResponseIsInstanceOfSlimFacadesHttpResponse() + public function testResponseIsInstanceOfSlimSupportHttpResponse() { $response = Response::getFacadeRoot(); @@ -39,7 +39,7 @@ public function testResponseIsPsrCompliant() } /** - * @depends testResponseIsInstanceOfSlimFacadesHttpResponse + * @depends testResponseIsInstanceOfSlimSupportHttpResponse * * @return void */ diff --git a/tests/Support/HelperFunctionsTest.php b/tests/Support/HelperFunctionsTest.php index 10f2526..0f1b514 100644 --- a/tests/Support/HelperFunctionsTest.php +++ b/tests/Support/HelperFunctionsTest.php @@ -1,14 +1,14 @@ expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Call to undefined method SlimFacades\Tests\Support\ForwardsCallsOne::missingMethod()'); + $this->expectExceptionMessage('Call to undefined method Affinity4\SlimSupport\Tests\Support\ForwardsCallsOne::missingMethod()'); (new ForwardsCallsOne)->missingMethod('foo', 'bar'); } @@ -32,7 +32,7 @@ public function testMissingForwardedCallThrowsCorrectError() public function testMissingAlphanumericForwardedCallThrowsCorrectError() { $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Call to undefined method SlimFacades\Tests\Support\ForwardsCallsOne::this1_shouldWork_too()'); + $this->expectExceptionMessage('Call to undefined method Affinity4\SlimSupport\Tests\Support\ForwardsCallsOne::this1_shouldWork_too()'); (new ForwardsCallsOne)->this1_shouldWork_too('foo', 'bar'); } @@ -40,7 +40,7 @@ public function testMissingAlphanumericForwardedCallThrowsCorrectError() public function testNonForwardedErrorIsNotTamperedWith() { $this->expectException(\Error::class); - $this->expectExceptionMessage('Call to undefined method SlimFacades\Tests\Support\ForwardsCallsBase::missingMethod()'); + $this->expectExceptionMessage('Call to undefined method Affinity4\SlimSupport\Tests\Support\ForwardsCallsBase::missingMethod()'); (new ForwardsCallsOne)->baseError('foo', 'bar'); } @@ -48,7 +48,7 @@ public function testNonForwardedErrorIsNotTamperedWith() public function testThrowBadMethodCallException() { $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Call to undefined method SlimFacades\Tests\Support\ForwardsCallsOne::test()'); + $this->expectExceptionMessage('Call to undefined method Affinity4\SlimSupport\Tests\Support\ForwardsCallsOne::test()'); (new ForwardsCallsOne)->throwTestException('test'); } diff --git a/tests/Support/Traits/MacroableTest.php b/tests/Support/Traits/MacroableTest.php index 37e1400..7682a4d 100644 --- a/tests/Support/Traits/MacroableTest.php +++ b/tests/Support/Traits/MacroableTest.php @@ -1,9 +1,9 @@