Skip to content

Commit

Permalink
Add Forge facade for Laravel integration
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Jun 2, 2024
1 parent 61a1441 commit 86e69ee
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
},
"laravel": {
"providers": [
"Laravel\\Forge\\ForgeServiceProvider"
]
}
},
"config": {
Expand Down
22 changes: 22 additions & 0 deletions src/Facades/Forge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Laravel\Forge\Facades;

use Laravel\Forge\ForgeManager;
use Illuminate\Support\Facades\Facade;

/**
* @mixin \Laravel\Forge\Forge
*/
class Forge extends Facade

Check failure on line 11 in src/Facades/Forge.php

View workflow job for this annotation

GitHub Actions / tests / Static Analysis

Class Laravel\Forge\Facades\Forge extends unknown class Illuminate\Support\Facades\Facade.
{
/**
* Get the registered name of the component.
*
* @return string
*/
public static function getFacadeAccessor()
{
return ForgeManager::class;
}
}
42 changes: 42 additions & 0 deletions src/ForgeManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Laravel\Forge;

use Illuminate\Support\Traits\ForwardsCalls;

/**
* @mixin \Laravel\Forge\Forge
*/
class ForgeManager
{
use ForwardsCalls;

Check failure on line 12 in src/ForgeManager.php

View workflow job for this annotation

GitHub Actions / tests / Static Analysis

Class Laravel\Forge\ForgeManager uses unknown trait Illuminate\Support\Traits\ForwardsCalls.

/**
* The Forge instance.
*
* @var \Laravel\Forge\Forge
*/
protected $forge;

/**
* Create a new Forge manager instance.
*
* @param string $token
*/
public function __construct($token)
{
$this->forge = new Forge($token);
}

/**
* Dynamically pass methods to the Forge instance.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call(string $method, array $parameters): mixed
{
return $this->forwardCallTo($this->forge, $method, $parameters);
}
}
19 changes: 19 additions & 0 deletions src/ForgeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Laravel\Forge;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;

class ForgeServiceProvider extends ServiceProvider

Check failure on line 8 in src/ForgeServiceProvider.php

View workflow job for this annotation

GitHub Actions / tests / Static Analysis

Class Laravel\Forge\ForgeServiceProvider extends unknown class Illuminate\Support\ServiceProvider.
{
/**
* Register any application services.
*/
public function register()
{
$this->app->singleton(ForgeManager::class, function ($app) {

Check failure on line 15 in src/ForgeServiceProvider.php

View workflow job for this annotation

GitHub Actions / tests / Static Analysis

Access to an undefined property Laravel\Forge\ForgeServiceProvider::$app.
return new ForgeManager($app['config']->get('services.forge.token'));
});
}
}

0 comments on commit 86e69ee

Please sign in to comment.