Skip to content

Commit

Permalink
Renaming package to slimphp-support. Updating all namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewatts committed Mar 9, 2024
1 parent a479966 commit d455f44
Show file tree
Hide file tree
Showing 33 changed files with 101 additions and 107 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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);
Expand All @@ -47,7 +47,7 @@ App::run();
### Container

```php
use SlimFacades\Facades\Container;
use Affinity4\SlimSupport\Facades\Container;

Container::set('some-service', function () {
return SomeService();
Expand All @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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 () {
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -12,15 +12,15 @@
],
"autoload": {
"psr-4": {
"SlimFacades\\": "src/"
"Affinity4\\SlimSupport\\": "src/"
},
"files": [
"./src/Support/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"SlimFacades\\Tests\\": "tests/"
"Affinity4\\SlimSupport\\Tests\\": "tests/"
}
},
"require": {
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Pipeline.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SlimFacades\Contracts;
namespace Affinity4\SlimSupport\Contracts;

use Closure;

Expand Down
5 changes: 2 additions & 3 deletions src/Facades/App.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php declare(strict_types=1);

namespace SlimFacades\Facades;
namespace Affinity4\SlimSupport\Facades;

use Psr\Http\Message\ResponseInterface;
use SlimFacades\Support\Facade;
use Affinity4\SlimSupport\Support\Facade;

/**
* @method static \Slim\Interfaces\RouteResolverInterface getRouteResolver()
Expand Down
4 changes: 2 additions & 2 deletions src/Facades/Container.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types=1);

namespace SlimFacades\Facades;
namespace Affinity4\SlimSupport\Facades;

use SlimFacades\Support\Facade;
use Affinity4\SlimSupport\Support\Facade;

/**
* @method static mixed get(string $id)
Expand Down
20 changes: 10 additions & 10 deletions src/Facades/Pipeline.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php declare(strict_types=1);

namespace SlimFacades\Facades;
namespace Affinity4\SlimSupport\Facades;

use SlimFacades\Support\Facade;
use SlimFacades\Support\Pipeline as PipelineBase;
use Affinity4\SlimSupport\Support\Facade;
use Affinity4\SlimSupport\Support\Pipeline as PipelineBase;

/**
* @method \SlimFacades\Support\Pipeline send(mixed $passable)
* @method \SlimFacades\Support\Pipeline through(array|mixed $pipes)
* @method \SlimFacades\Support\Pipeline pipe(array|mixed $pipes)
* @method \SlimFacades\Support\Pipeline via(string $method)
* @method \SlimFacades\Support\Pipeline then(\Closure $destination)
* @method \Affinity4\SlimSupport\Support\Pipeline send(mixed $passable)
* @method \Affinity4\SlimSupport\Support\Pipeline through(array|mixed $pipes)
* @method \Affinity4\SlimSupport\Support\Pipeline pipe(array|mixed $pipes)
* @method \Affinity4\SlimSupport\Support\Pipeline via(string $method)
* @method \Affinity4\SlimSupport\Support\Pipeline then(\Closure $destination)
* @method mixed thenReturn()
* @method \SlimFacades\Support\PipelineBase getContainer()
* @method \SlimFacades\Support\PipelineBase setContainer(ContainerInterface $container)
* @method \Affinity4\SlimSupport\Support\PipelineBase getContainer()
* @method \Affinity4\SlimSupport\Support\PipelineBase setContainer(ContainerInterface $container)
*/
class Pipeline extends Facade
{
Expand Down
8 changes: 4 additions & 4 deletions src/Facades/Response.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php declare(strict_types=1);

namespace SlimFacades\Facades;
namespace Affinity4\SlimSupport\Facades;

use SlimFacades\Http\Response as HttpResponse;
use SlimFacades\Support\Facade;
use Affinity4\SlimSupport\Http\Response as HttpResponse;
use Affinity4\SlimSupport\Support\Facade;

/**
* @method static \Psr\Http\Message\ResponseInterface get()
* @method static \SlimFacades\Http\Response json(array $data)
* @method static \Affinity4\SlimSupport\Http\Response json(array $data)
*/
class Response extends Facade
{
Expand Down
4 changes: 2 additions & 2 deletions src/Facades/ResponseFactory.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types=1);

namespace SlimFacades\Facades;
namespace Affinity4\SlimSupport\Facades;

use SlimFacades\Support\Facade;
use Affinity4\SlimSupport\Support\Facade;

/**
* @method static \Psr\Http\Message\ResponseFactoryInterface createResponse(int $code = 200, string $reasonPhrase = '')
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types=1);

namespace SlimFacades\Http;
namespace Affinity4\SlimSupport\Http;

use SlimFacades\Facades\ResponseFactory;
use Affinity4\SlimSupport\Facades\ResponseFactory;
use Psr\Http\Message\ResponseInterface;

class Response
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Facade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SlimFacades\Support;
namespace Affinity4\SlimSupport\Support;

abstract class Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/Support/HigherOrderTapProxy.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SlimFacades\Support;
namespace Affinity4\SlimSupport\Support;

class HigherOrderTapProxy
{
Expand Down
2 changes: 1 addition & 1 deletion src/Support/HigherOrderWhenProxy.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SlimFacades\Support;
namespace Affinity4\SlimSupport\Support;

class HigherOrderWhenProxy
{
Expand Down
4 changes: 2 additions & 2 deletions src/Support/Hub.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace SlimFacades\Support;
namespace Affinity4\SlimSupport\Support;

use Psr\Container\ContainerInterface;
use SlimFacades\Support\Pipeline;
use Affinity4\SlimSupport\Support\Pipeline;

class Hub
{
Expand Down
6 changes: 3 additions & 3 deletions src/Support/Pipeline.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SlimFacades\Support;
namespace Affinity4\SlimSupport\Support;

use Psr\Container\ContainerInterface;
use SlimFacades\Contracts\Pipeline as PipelineContract;
use SlimFacades\Support\Traits\Conditionable;
use Affinity4\SlimSupport\Contracts\Pipeline as PipelineContract;
use Affinity4\SlimSupport\Support\Traits\Conditionable;

class Pipeline implements PipelineContract
{
Expand Down
4 changes: 2 additions & 2 deletions src/Support/Traits/Conditionable.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace SlimFacades\Support\Traits;
namespace Affinity4\SlimSupport\Support\Traits;

use Closure;
use SlimFacades\Support\HigherOrderWhenProxy;
use Affinity4\SlimSupport\Support\HigherOrderWhenProxy;

trait Conditionable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Traits/Dumpable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SlimFacades\Support\Traits;
namespace Affinity4\SlimSupport\Support\Traits;

trait Dumpable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Traits/ForwardsCalls.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SlimFacades\Support\Traits;
namespace Affinity4\SlimSupport\Support\Traits;

trait ForwardsCalls
{
Expand Down
19 changes: 7 additions & 12 deletions src/Support/Traits/Macroable.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?php

namespace SlimFacades\Support\Traits;

use BadMethodCallException;
use Closure;
use ReflectionClass;
use ReflectionMethod;
namespace Affinity4\SlimSupport\Support\Traits;

trait Macroable
{
Expand Down Expand Up @@ -39,8 +34,8 @@ public static function macro($name, $macro)
*/
public static function mixin($mixin, $replace = true)
{
$methods = (new ReflectionClass($mixin))->getMethods(
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED
$methods = (new \ReflectionClass($mixin))->getMethods(
\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED
);

foreach ($methods as $method) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Support/Traits/Tappable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SlimFacades\Support\Traits;
namespace Affinity4\SlimSupport\Support\Traits;

trait Tappable
{
Expand All @@ -14,4 +14,4 @@ public function tap($callback = null)
{
return tap($this, $callback);
}
}
}
4 changes: 2 additions & 2 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);

use SlimFacades\Http\Response;
use SlimFacades\Support\HigherOrderTapProxy;
use Affinity4\SlimSupport\Http\Response;
use Affinity4\SlimSupport\Support\HigherOrderTapProxy;

if (!function_exists('response')) {
/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Facades/AppTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php declare(strict_types=1);

namespace SlimFacades\Tests\Facades;
namespace Affinity4\SlimSupport\Tests\Facades;

use DI\Bridge\Slim\Bridge;
use DI\Container;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use SlimFacades\Facades\App;
use SlimFacades\Support\Facade;
use Affinity4\SlimSupport\Facades\App;
use Affinity4\SlimSupport\Support\Facade;

final class AppTest extends TestCase
{
Expand Down
Loading

0 comments on commit d455f44

Please sign in to comment.