rfc:complete_callstatc_magic
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:complete_callstatc_magic [2024/03/29 02:19] – daddyofsky | rfc:complete_callstatc_magic [2024/03/29 04:32] (current) – daddyofsky | ||
---|---|---|---|
Line 53: | Line 53: | ||
However, the IDE cannot find **active** method, and the **Go to Definition** feature cannot be used. | However, the IDE cannot find **active** method, and the **Go to Definition** feature cannot be used. | ||
- | Somewhere in the internal code, there is code that matches the **active** method to the **scopeActive** method, but it's hidden, not easy to find. | + | Somewhere in the internal code not in _ _callStatic, there is code that matches the **active** method to the **scopeActive** method, but it's hidden, not easy to find. |
Line 145: | Line 145: | ||
Aside from the fact that the method is not static, this code is very clear too. | Aside from the fact that the method is not static, this code is very clear too. | ||
+ | |||
+ | |||
+ | |||
+ | ==== Case 3 ==== | ||
+ | |||
+ | Let's make a custom facade in Laravel. | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | // 1. app/ | ||
+ | namespace App\Services; | ||
+ | |||
+ | class CustomService | ||
+ | { | ||
+ | public function someMethod() {} | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | // 2. app/ | ||
+ | namespace App\Facades; | ||
+ | |||
+ | use Illuminate\Support\Facades\Facade; | ||
+ | |||
+ | class CustomFacade extends Facade | ||
+ | { | ||
+ | protected static function getFacadeAccessor() | ||
+ | { | ||
+ | return ' | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | // 3. app/ | ||
+ | namespace App\Providers; | ||
+ | |||
+ | use Illuminate\Support\ServiceProvider; | ||
+ | use App\Services\CustomService; | ||
+ | |||
+ | class AppServiceProvider extends ServiceProvider | ||
+ | { | ||
+ | public function register() | ||
+ | { | ||
+ | $this-> | ||
+ | return new CustomService(); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | use App\Facades\CustomFacade; | ||
+ | |||
+ | CustomFacade:: | ||
+ | </ | ||
+ | |||
+ | |||
+ | Now what if this RFC is accepted? | ||
+ | |||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | // 1. app/ | ||
+ | namespace App\Services; | ||
+ | |||
+ | class CustomService | ||
+ | { | ||
+ | public static __callStatic($method, | ||
+ | { | ||
+ | return (new static())-> | ||
+ | } | ||
+ | |||
+ | public function someMethod() {} | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | use App\Services\CustomService; | ||
+ | |||
+ | CustomService:: | ||
+ | </ | ||
+ | |||
+ | That's it. | ||
+ | |||
+ | ---------------------- | ||
rfc/complete_callstatc_magic.1711678791.txt.gz · Last modified: 2024/03/29 02:19 by daddyofsky