Skip to content

Commit

Permalink
Save services from app service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
v1p3r75 committed Mar 17, 2024
1 parent dc13034 commit 9b22a53
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 115 deletions.
27 changes: 4 additions & 23 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ public static function getInstance(?string $root_dir = null, bool $isConsole = f
}

/**
* Save all applications services (middlewares, consoles, etc)
* Save all applications services
*/
private function saveAppServices(array $services)
private function saveAppServices()
{

foreach ($services as $service) {

(new $service)->register();
}
return (new \App\Providers\AppServiceProvider)->register();
}

public function services(): Container
Expand All @@ -98,9 +95,7 @@ public function run()

require(__DIR__ . "/Helpers.php"); // load function helpers

$services = $this->getAllServices();

$this->saveAppServices($services);
$this->saveAppServices();

// Collect GET, POST, PUT, PATCH, DELETE together
$requestData = $this->collectRequestData();
Expand All @@ -125,20 +120,6 @@ private function dispatch(Request $request, Kernel $kernel)
}


public function getAllServices(): array
{

$servicesKernelPath = core_services_path("Kernel.php");

$appServicesPath = app_services_path("Kernel.php");

$appServices = require($appServicesPath);

$servicesKernel = require($servicesKernelPath);

return [...$servicesKernel, ...$appServices];
}

public static function getHttpKernel()
{
$appHttpKernel = app_http_path("Kernel.php");
Expand Down
34 changes: 0 additions & 34 deletions src/Console/Commands/MakeService.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Floky\Console\Commands\MakeController::class,
Floky\Console\Commands\MakeMiddleware::class,
Floky\Console\Commands\MakeRequest::class,
Floky\Console\Commands\MakeService::class,
Floky\Console\Commands\MakeCommand::class,
Floky\Console\Commands\MakeResource::class,
Floky\Console\Commands\MakeModel::class,
Expand Down
2 changes: 0 additions & 2 deletions src/Console/Stubs/controller.make.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http\Controllers;

use Floky\Http\Controllers\Controller;

class {{name}} extends Controller
{

Expand Down
22 changes: 0 additions & 22 deletions src/Console/Stubs/service.make.stub

This file was deleted.

6 changes: 3 additions & 3 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ function app_resources_path(string $path = "")
}
}

if (!function_exists('app_services_path')) {
function app_services_path(string $path = "")
if (!function_exists('app_providers_path')) {
function app_providers_path(string $path = "")
{

return app_path("Services/$path");
return app_path("Providers/$path");
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Http/Requests/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class Request

public static ?Request $instance = null;

public string $attr = "start"; /* Just for middlewares testing */

public static array $data = [];

public static function getInstance()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Floky\Services;
namespace Floky\Providers;

use Closure;
use Floky\Application;
use Floky\Http\Requests\Request;

abstract class ServiceProvider
{
Expand All @@ -13,6 +13,11 @@ abstract class ServiceProvider
public function __construct()
{
$this->app = Application::getInstance();

$this->app->services()->set(Request::class, function() {

return Request::getInstance();
});
}

abstract public function register();
Expand Down
19 changes: 0 additions & 19 deletions src/Services/Internal/RequestService.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Services/Kernel.php

This file was deleted.

0 comments on commit 9b22a53

Please sign in to comment.