-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from flightphp/container
Added Containerization to Core
- Loading branch information
Showing
12 changed files
with
616 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,24 +19,25 @@ | |
* @copyright Copyright (c) 2011, Mike Cao <[email protected]> | ||
* | ||
* # Core methods | ||
* @method static void start() Starts the framework. | ||
* @method static void path(string $path) Adds a path for autoloading classes. | ||
* @method static void stop(?int $code = null) Stops the framework and sends a response. | ||
* @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true) | ||
* @method static void start() Starts the framework. | ||
* @method static void path(string $path) Adds a path for autoloading classes. | ||
* @method static void stop(?int $code = null) Stops the framework and sends a response. | ||
* @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true) | ||
* Stop the framework with an optional status code and message. | ||
* @method static void registerContainerHandler(callable|object $containerHandler) Registers a container handler. | ||
* | ||
* # Routing | ||
* @method static Route route(string $pattern, callable $callback, bool $pass_route = false, string $alias = '') | ||
* @method static Route route(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') | ||
* Maps a URL pattern to a callback with all applicable methods. | ||
* @method static void group(string $pattern, callable $callback, callable[] $group_middlewares = []) | ||
* Groups a set of routes together under a common prefix. | ||
* @method static Route post(string $pattern, callable $callback, bool $pass_route = false, string $alias = '') | ||
* @method static Route post(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') | ||
* Routes a POST URL to a callback function. | ||
* @method static Route put(string $pattern, callable $callback, bool $pass_route = false, string $alias = '') | ||
* @method static Route put(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') | ||
* Routes a PUT URL to a callback function. | ||
* @method static Route patch(string $pattern, callable $callback, bool $pass_route = false, string $alias = '') | ||
* @method static Route patch(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') | ||
* Routes a PATCH URL to a callback function. | ||
* @method static Route delete(string $pattern, callable $callback, bool $pass_route = false, string $alias = '') | ||
* @method static Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') | ||
* Routes a DELETE URL to a callback function. | ||
* @method static Router router() Returns Router instance. | ||
* @method static string getUrl(string $alias, array<string, mixed> $params = []) Gets a url from an alias | ||
|
@@ -101,34 +102,6 @@ private function __clone() | |
{ | ||
} | ||
|
||
/** | ||
* Registers a class to a framework method. | ||
* | ||
* # Usage example: | ||
* ``` | ||
* Flight::register('user', User::class); | ||
* | ||
* Flight::user(); # <- Return a User instance | ||
* ``` | ||
* | ||
* @param string $name Static method name | ||
* @param class-string<T> $class Fully Qualified Class Name | ||
* @param array<int, mixed> $params Class constructor params | ||
* @param ?Closure(T $instance): void $callback Perform actions with the instance | ||
* | ||
* @template T of object | ||
*/ | ||
public static function register($name, $class, $params = [], $callback = null): void | ||
{ | ||
static::__callStatic('register', [$name, $class, $params, $callback]); | ||
} | ||
|
||
/** Unregisters a class. */ | ||
public static function unregister(string $methodName): void | ||
{ | ||
static::__callStatic('unregister', [$methodName]); | ||
} | ||
|
||
/** | ||
* Handles calls to static methods. | ||
* | ||
|
@@ -140,7 +113,7 @@ public static function unregister(string $methodName): void | |
*/ | ||
public static function __callStatic(string $name, array $params) | ||
{ | ||
return Dispatcher::invokeMethod([self::app(), $name], $params); | ||
return self::app()->{$name}(...$params); | ||
} | ||
|
||
/** @return Engine Application instance */ | ||
|
Oops, something went wrong.