Ray.Di for Laravel

Related tags

Laravel laravel aop di
Overview

Ray.Di for Laravel

English | Japanese

In addition to the existing Laravel service container, Ray.Di provides dependency resolution for contoroller. AOP can be applied to all injected objects.

Installation

composer require ray/ray-di-for-laravel

Use

Copy the module that describes the binding.

cp -r vendor/ray/ray-di-for-laravel/Ray app

Add the following line to bootstrap/app.php.

use App\Ray\Module;
use App\RayRouter;
use Ray\Di\Injector;
$app['router'] = new RayRouter($app['events'], $app, new Injector(new Module()));

Demo

See hello-ray-di-for-laravel demo code.

You might also like...
Laravel Larex lets you translate your whole Laravel application from a single CSV file.
Laravel Larex lets you translate your whole Laravel application from a single CSV file.

Laravel Larex Translate Laravel Apps from a CSV File Laravel Larex lets you translate your whole Laravel application from a single CSV file. You can i

A Laravel package that adds a simple image functionality to any Laravel model
A Laravel package that adds a simple image functionality to any Laravel model

Laraimage A Laravel package that adds a simple image functionality to any Laravel model Introduction Laraimage served four use cases when using images

A Laravel extension for using a laravel application on a multi domain setting
A Laravel extension for using a laravel application on a multi domain setting

Laravel Multi Domain An extension for using Laravel in a multi domain setting Description This package allows a single Laravel installation to work wi

Example of using abrouter/abrouter-laravel-bridge in Laravel
Example of using abrouter/abrouter-laravel-bridge in Laravel

ABRouter Laravel Example It's a example of using (ABRouter Laravel Client)[https://github.com/abrouter/abrouter-laravel-bridge] Set up locally First o

Laravel router extension to easily use Laravel's paginator without the query string

🚨 THIS PACKAGE HAS BEEN ABANDONED 🚨 We don't use this package anymore in our own projects and cannot justify the time needed to maintain it anymore.

Laravel application project as Sheina Online Store backend to be built with Laravel and VueJS

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis Features Work with geometry classes instead of arrays. $model-myPoint = new Point(1,2); //lat

laravel - Potion is a pure PHP asset manager for Laravel 5 based off of Assetic.

laravel-potion Potion is a pure PHP asset manager for Laravel based off of Assetic. Description Laravel 5 comes with a great asset manager called Elix

Llum illuminates your Laravel projects speeding up your Github/Laravel development workflow
Llum illuminates your Laravel projects speeding up your Github/Laravel development workflow

Llum illuminates your Laravel projects speeding up your Github/Laravel development workflow

Comments
  • Override application class

    Override application class

    RouteとRouterの差し替えとは異なる手法の提案PRです。

    Illuminate\Foundation\Applicationクラスを差し替えることで、コントローラのほかにミドルウェア、コンソールコマンドなどもRayを用いた依存解決が可能になります。

    コントローラ以外はRouteのような容易に入れ替え可能なファクトリ相当のクラスがほとんどなく、それであればいっそ中核を変更した方が手っ取り早いという方針です。

    Illuminate\Container\Container::resolve() (及びそれを継承したIlluminate\Foundation\Application::resolve()) が依存解決の中枢なのでそこにRayによる解決を差し込んでいます。 依存の束縛用のメソッドであるsingleton()、bind()などは下手に変えないほうが良さそうなのでノータッチです。

    アプリ側の利用例は下記のような感じです。 https://github.com/koriym/hello-ray-di-for-laravel/compare/master...n1215:override-application?expand=1

    ※ この手法で問題なさそうであればRoute、Routerの上書きは不要になりますが一旦そのままにしてます。

    opened by n1215 30
  • Context に応じた Injector を利用可能に

    Context に応じた Injector を利用可能に

    概要

    CachedInjectorFactory を使い、context に応じて利用する injector を変更できるようにします。

    方法

    bootstrap

    次のような bootstrap になります。

    - $app = new Illuminate\Foundation\Application(
    -     $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
    - );
    + $app = new Ray\RayDiForLaravel\ApplicationFactory(
    +     $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__),
    +     new PrdContext($_ENV['APP_BASE_PATH'] ?? dirname(__DIR__))
    + );
    
    enhancement 
    opened by NaokiTsuchiya 6
  • Please improve response time.

    Please improve response time.

    I have installed a Laravel telescope to track request times, and in my case, a simple controller returns a view and using a logger logs it to the storage directory.

    When I send a request to the home page without Aop the response time is around 538ms, But when I send a request to a home with enabled Aop the request time is 1215ms.

    Loggable Attribute:

    <?php
    
    declare(strict_types=1);
    
    namespace App\Attribute;
    
    use Attribute;
    use Ray\Di\Di\Qualifier;
    
    #[Attribute, Qualifier]
    final class Loggable
    {
    }
    

    LoggerInterceptor:

    <?php
    
    declare(strict_types=1);
    
    namespace App\Interceptor;
    use Ray\Aop\MethodInterceptor;
    use Ray\Aop\MethodInvocation;
    use function microtime;
    
    final class LoggerInterceptor implements MethodInterceptor
    {
        public function invoke(MethodInvocation $invocation)
        {
            \Illuminate\Support\Facades\Log::info('Welcome view proccessed.');
        }
    }
    

    Controller:

    <?php
    
    namespace App\Http\Controllers;
    
    use App\Attribute\Loggable;
    use App\Domain\Double\DoubleInterface;
    use Ray\Di\Di\Inject;
    use Ray\Di\Di\PostConstruct;
    use Ray\Di\Di\Set;
    use Ray\Di\ProviderInterface;
    
    class HelloController extends Controller
    {
        #[Loggable]
        public function index()
        {
            return view('welcome');
        }
    }
    
    opened by kindslayer 3
Releases(0.1.0)
  • 0.1.0(Oct 17, 2022)

    What's Changed

    • Support Laravel 8 by @NaokiTsuchiya in https://github.com/ray-di/Ray.RayDiForLaravel/pull/1
    • Override application class by @n1215 in https://github.com/ray-di/Ray.RayDiForLaravel/pull/2
    • Context に応じた Injector を利用可能に by @NaokiTsuchiya in https://github.com/ray-di/Ray.RayDiForLaravel/pull/4
    • Require ray/compiler:^1.9.1 by @NaokiTsuchiya in https://github.com/ray-di/Ray.RayDiForLaravel/pull/5
    • Add context class by @NaokiTsuchiya in https://github.com/ray-di/Ray.RayDiForLaravel/pull/6
    • Add GitHub workflows by @NaokiTsuchiya in https://github.com/ray-di/Ray.RayDiForLaravel/pull/7
    • Add php82 test by @NaokiTsuchiya in https://github.com/ray-di/Ray.RayDiForLaravel/pull/8

    New Contributors

    • @NaokiTsuchiya made their first contribution in https://github.com/ray-di/Ray.RayDiForLaravel/pull/1
    • @n1215 made their first contribution in https://github.com/ray-di/Ray.RayDiForLaravel/pull/2

    Full Changelog: https://github.com/ray-di/Ray.RayDiForLaravel/commits/0.1.0

    Source code(tar.gz)
    Source code(zip)
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Erik C. Forés 31 Dec 18, 2022
Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster.

Laravel Kickstart What is Laravel Kickstart? Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster. It com

Sam Rapaport 46 Oct 1, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application.

Laravel Segment Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application. Installation You can install the pac

Octohook 13 May 16, 2022
Laravel Sanctum support for Laravel Lighthouse

Lighthouse Sanctum Add Laravel Sanctum support to Lighthouse Requirements Installation Usage Login Logout Register Email Verification Forgot Password

Daniël de Wit 43 Dec 21, 2022
Bring Laravel 8's cursor pagination to Laravel 6, 7

Laravel Cursor Paginate for laravel 6,7 Installation You can install the package via composer: composer require vanthao03596/laravel-cursor-paginate U

Pham Thao 9 Nov 10, 2022
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
Laravel Jetstream is a beautifully designed application scaffolding for Laravel.

Laravel Jetstream is a beautifully designed application scaffolding for Laravel. Jetstream provides the perfect starting point for your next Laravel application and includes login, registration, email verification, two-factor authentication, session management, API support via Laravel Sanctum, and optional team management.

The Laravel Framework 3.5k Jan 8, 2023