Examples of using each Illuminate component in non-Laravel applications

Overview

Torch logo

Torch - Using Laravel's Illuminate Components Independently

Torch is a project to provide instructions and examples for using Illuminate components as standalone components in non-Laravel applications. The current master branch shows how to use Illuminate's 8.0 components.

Note: If you are working with an older project, you might have more success using the 5.5 components or the 5.1 components or the 4.2 components.

Usage

At the moment, the project is divided into many directories beneath components which will each contain an index file, usually written with Slim. Navigate to that directory in your terminal and run the following to serve a web site from that directory:

$ composer install
$ php -S localhost:8000

Now you can visit http://localhost:8000/ in your browser to view the output of each.

Packages

Ready for 8.0

Need to be moved over from 4.2

  • Mail - Never finished porting from 4.2-5.1 and then it never got the simpler upgrades from 5.1 until today

Other Packages

Done

Contributing

A few important notes:

  1. The imagined end user is a developer of any Symfony-HttpFoundation-using project copying the route closure directly into a project, so try to avoid using any Slim conventions and use as little preparation code outside the closure as possible.
  2. While some components would be easier to implement with a Laravel-style Application instance and a fuller bootstrap, I'd prefer we implement as many as possible without loading Laravel's Service Providers.
  3. Some components will require a bootstrap, and I hope we can come up with a Best-Practice bootstrap and Laravel-style Application instance for loading Service Providers, etc.

Contributing

The most helpful use for contributions right now would be updating the readme's in each section to make sure we have instructions on how to test this specific component to see that it's working (based on how the specific index.php for this component is set up).

But my framework doesn't use Symfony's HttpFoundation!

Many of these components will still work. But a few of them require HttpFoundation. ¯\(°_o)/¯

Comments
  • Sessions working?

    Sessions working?

    Hi, is the Sessions component still working, now with 5.4 version?

    I tried to install it, but they never got stored on the right folder. I'm using all components on 5.4.

    opened by rafaelcanical 17
  • Finish updating all components to 5.5

    Finish updating all components to 5.5

    You can see the current list in the README but I'm encapsulating this here for the purpose of asking for help.

    Here's what it takes to "move a component over":

    1. Find the correct Issue (see those linked in the comments below) for the given component. Leave a comment in that issue showing you'll be pulling this task.
    2. Grab the code for that component from the older branch and put it into the appropriate folder in the newer branch. Or, more likely, it's sitting in the newer branch, just still with the old code and Composer dependencies. Just update it in place.
    3. Update the composer.json references to Laravel "~5.5.0"
    4. Try to composer install; see if anything breaks and whether you also need to update the versions of any other dependencies, or add or remove any others
    5. Once composer install works, spin up the PHP server (php -S localhost:8080) and then visit each route that's defined in that component's index.php (e.g. http://localhost:8080/ for the root of the component you're testing) and test whether everything works as expected
    6. If it all works, PR it! If you get stuck, PR where you are with notes about what got stuck.

    Need to move from the Laravel 5.1 branch:

    Need to be finished moving from the Laravel 4.2 branch (imported but needs to be tested and tweaked):

    enhancement help wanted 
    opened by mattstauffer 14
  • [WIP] Artisan Component

    [WIP] Artisan Component

    Opening this early for discussion/question asking. Trying to work on the artisan component, the main issue at the moment is that composer require illuminate/foundation fails, and the main thing we need is the foundation app.

    You can get around this by rewriting chunk of artisan, but I feel like that's against the "spirit" of what this project is trying to accomplish.

    opened by hskrasek 11
  • Add Queue Component for 5.5

    Add Queue Component for 5.5

    Based off your queue branch, but with a few changes. Open to feedback on improving the submission.

    Changes:

    • I removed the use of configs as I felt that hid the setup of the Queue component rather than showing how to interact with it.
    • I had issues getting Beanstalkd to work properly, so I went with Redis.

    The workers were a bit challenging. It requires an ExceptionHandler, so I created one as an anonymous class. If there's an easier/better way to create one, let me know.

    When running as a daemon, it is expecting an Application as it makes a call to isDownForMaintenance. To solve this I created an "App" and added the method. The daemon also ran fine, but then locked up.

    Thank you for Torch! It's been a nice reference. Glad I can contribute in some small way.

    Fixed #83

    opened by mloberg 9
  • Acessing request and container instances from route

    Acessing request and container instances from route

    @mattstauffer Hey. Given the routing index.php example in the master branch. I do something like this

     $configPath = __DIR__ . '/../config/';
        
        $array = [
            'site' => require $configPath . 'site.php',
            'db' => require $configPath . 'database.php'
        ];
        
        $config = new Config($array);
    
        // Create a service container
        $container = new Container;
    
        $request = Request::capture();
        
        $container->instance('Illuminate\Http\Request', $request);
        $container->instance('config', $config);
    

    After which, routes.php is required into the app.

    <?php
        use Illuminate\Routing\Router;
    
        $router->get('/', function () {
            return $config->get('site.setup');
        });
    

    How could I access the config in here?

    opened by randohinn 8
  • Anonymous Balde X components not working

    Anonymous Balde X components not working

    Hello. I am running components/view as it is mentioned here https://github.com/mattstauffer/Torch/tree/master/components/view#usage, but when I try adding anonymous component, I get an error.

    Updated templates/page.blade.php:

    @extends('layout')
    
    @section('content')
    
        <h1>{{ $title }}</h1>
        <p>{{ $text }}</p>
    
        <x-alert type="success" message="Good luck!" />
    
    @endsection
    

    The templates/components/alert.blade.php:

    @props([
        'type' => 'info',
        'message'
    ])
    
    <div {{ $attributes->merge(['class' => 'alert alert-' . $type]) }}>
        {{ $message }}
    </div>
    

    The error:

    Illuminate\Contracts\Container\BindingResolutionException thrown with message 
    "Target [Illuminate\Contracts\View\Factory] is not instantiable."
    
    Stacktrace:
    #33 Illuminate\Contracts\Container\BindingResolutionException in 
    C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:1017
    #32 Illuminate\Container\Container:notInstantiable in 
    C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:818
    #31 Illuminate\Container\Container:build in C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:691
    #30 Illuminate\Container\Container:resolve in C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:637
    #29 Illuminate\Container\Container:make in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:221
    #28 Illuminate\View\Compilers\ComponentTagCompiler:componentClass in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:185
    #27 Illuminate\View\Compilers\ComponentTagCompiler:componentString in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:170
    #26 Illuminate\View\Compilers\ComponentTagCompiler:Illuminate\View\Compilers\{closure} in [internal]:0
    #25 preg_replace_callback in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:165
    #24 Illuminate\View\Compilers\ComponentTagCompiler:compileSelfClosingTags in             
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:79
    #23 Illuminate\View\Compilers\ComponentTagCompiler:compileTags in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:66
    #22 Illuminate\View\Compilers\ComponentTagCompiler:compile in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\BladeCompiler.php:322
    #21 Illuminate\View\Compilers\BladeCompiler:compileComponentTags in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\BladeCompiler.php:222
    #20 Illuminate\View\Compilers\BladeCompiler:compileString in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\BladeCompiler.php:143
    #19 Illuminate\View\Compilers\BladeCompiler:compile in 
    C:\OpenServer\domains\view\vendor\illuminate\view\Engines\CompilerEngine.php:51
    #18 Illuminate\View\Engines\CompilerEngine:get in C:\OpenServer\domains\view\vendor\illuminate\view\View.php:139
    #17 Illuminate\View\View:getContents in C:\OpenServer\domains\view\vendor\illuminate\view\View.php:122
    #16 Illuminate\View\View:renderContents in C:\OpenServer\domains\view\vendor\illuminate\view\View.php:91
    #15 Illuminate\View\View:render in C:\OpenServer\domains\view\index.php:57
    #14 Closure:{closure} in C:\OpenServer\domains\view\vendor\slim\slim\Slim\Handlers\Strategies\RequestResponse.php:40
    #13 call_user_func in C:\OpenServer\domains\view\vendor\slim\slim\Slim\Handlers\Strategies\RequestResponse.php:40
    #12 Slim\Handlers\Strategies\RequestResponse:__invoke in 
    C:\OpenServer\domains\view\vendor\slim\slim\Slim\Route.php:281
    #11 Slim\Route:__invoke in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:117
    #10 Slim\Route:callMiddlewareStack in C:\OpenServer\domains\view\vendor\slim\slim\Slim\Route.php:268
    #9 Slim\Route:run in C:\OpenServer\domains\view\vendor\slim\slim\Slim\App.php:503
    #8 Slim\App:__invoke in C:\OpenServer\domains\view\vendor\zeuxisoo\slim- 
    whoops\src\Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware.php:31
    #7 Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware:__invoke in 
    C:\OpenServer\domains\view\vendor\slim\slim\Slim\DeferredCallable.php:57
    #6 call_user_func_array in C:\OpenServer\domains\view\vendor\slim\slim\Slim\DeferredCallable.php:57
    #5 Slim\DeferredCallable:__invoke in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:70
    #4 call_user_func in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:70
    #3 Slim\App:Slim\{closure} in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:117
    #2 Slim\App:callMiddlewareStack in C:\OpenServer\domains\view\vendor\slim\slim\Slim\App.php:392
    #1 Slim\App:process in C:\OpenServer\domains\view\vendor\slim\slim\Slim\App.php:297
    #0 Slim\App:run in C:\OpenServer\domains\view\index.php:60
    

    Please help.

    opened by lexdubyna 7
  • Bump Routing to 5.6, include Middleware

    Bump Routing to 5.6, include Middleware

    Note: this branch is rebased on PR #66 so there's some duplication. Can adjust if needed.

    • Routing component bumped to Laravel 5.6. No additional changes were required.
    • Middleware examples were merged into Routing component, and are no longer separated. All code is up-to-date for 5.6.
    opened by AkenRoberts 7
  • Started porting components to 5.5

    Started porting components to 5.5

    Started porting components to 5.5. Already ported the following components:

    • Logs
    • Config
    • Encryption

    Working on more components in the following days.

    opened by Rubemlrm 7
  • How to use DB::raw?

    How to use DB::raw?

    In the documentation http://laravel.com/docs/5.1/queries#selects, there is a section Raw Expressions which is an example of code to use raw expressions

    $users = DB::table('users')
                         ->select(DB::raw('count(*) as user_count, status'))
                         ->where('status', '<>', 1)
                         ->groupBy('status')
                         ->get();
    

    And how it can be used without a framework?

    opened by dead23angel 7
  • Routing component, implement middleware

    Routing component, implement middleware

    Hi,

    first of all let me congratulate your for your amazing work. I'm currently experimenting things, and I'm focusing essentially on the Routing component. I currently have a micro app with the router implemented with some Controllers.

    My question is, is it complicated to implement middlewares? What should I do to make this possible? Could you point me in the right direction please?

    Thanks :+1:

    opened by rafaelcanical 5
  • Cache Component

    Cache Component

    Adding the cache component. @mattstauffer do you want another driver done? Something like redis or memcache would require those services to be running locally if you wanted to test them in the browser.

    Signed-off-by: Hunter Skrasek [email protected]

    opened by hskrasek 5
  • route name

    route name

    Hi dear I create app and route helper method same laravel helper methods and my code this is: function app($abstract = null, array $parameters = []) { if (is_null($abstract)) { return Container::getInstance(); }

    `return Container::getInstance()->make($abstract, $parameters);`
    

    } function route($name, $parameters = [], $absolute = true) { return app('url')->route($name, $parameters, $absolute); } but when call route and send route name for example route('profile') i have this error:

    Fatal error: Uncaught ReflectionException: Class url does not exist in vendor\illuminate\container\Container.php:877 I think laravel use RoutingServiceProvider and I need provider please help thanks

    opened by mitisa 0
  • Add a component example for illuminate/mail

    Add a component example for illuminate/mail

    Hey @mattstauffer,

    Big fan of the work you have done on using illuminate components outside of Laravel and recently had to upgrade a project from using illuminate/mail 4.2 to 7 so thought I would contribute a PR.

    Implementing queue support is a little more complex but let me know if you want me to include that as well.

    Hopefully the style and approach is inline with other component examples and please let me know if you would prefer any refactors :-)

    Cheers!

    opened by mrtimp 0
  • Making Cache, Config, and Env work in harmony (example)

    Making Cache, Config, and Env work in harmony (example)

    Hey @mattstauffer ,

    This might supersede #192 idea and prior PR. Here is an example of how to get Cache, Config, and Env.

    Some notes:

    1. Not sure one would want to, but Illuminate\Support\Arr is needed to parse output of Cache::get(...) as it doesn't handle dot notation.
    2. I can't beat Laravel's logic for handling cache/env for different environments. Not sure how that would be demonstrated other than copy/pasting from their source code.

    Works-for-me example code:

    <?PHP
    
    /*
      Note, these variables aren't directly accessible. Use globals
      EG: Illuminate\Support\Facades\Config::get("app.cnx")
     */
    
    use Illuminate\Container\Container;
    use Illuminate\Support\Arr;
    use Illuminate\Config\Repository;
    use Illuminate\Support\Facades\Facade;
    use Illuminate\Filesystem\Filesystem;
    use Illuminate\Cache\CacheManager;
    use Dotenv\Dotenv;
    use Illuminate\Support\Facades\Config;
    use Illuminate\Support\Facades\Cache;
    use Illuminate\Support\Env;
    
    defined("FILE_ROOT") ? true : define("FILE_ROOT", realpath(".."));
    
    // create dummy app
    $app = new Container();
    
    
    // would want to refactor to make sure cache is used in production
    try {
        // check if file exists. if not, presume production enviroment
        $dotenv = Dotenv::createImmutable(FILE_ROOT);
        $dotenv->load();
    } catch (Exception $e) {
        // presume production
        error_log($e->getMessage());
    }
    
    // config setup
    $config = new Repository(require(FILE_ROOT . "/backend/config/app.php"));
    
    // bind $config to $app
    $app->instance(
        'config',
        $config
    );
    
    // cache stuff
    $cacheC = new Container();
    $cacheC['config'] = $config->get('app.cache');
    $cacheC["files"] = new Filesystem();
    $cacheManager = new CacheManager($cacheC);
    $cache = $cacheManager->store();
    
    // bind $cache to $app
    $app->instance(
        'cache',
        $cache
    );
    
    $cache->put('test', 'This is loaded from Redis cache.', 500);
    $cache->put('app', $config->get('app'));
    
    $config->set('test', 'rofl');
    
    Facade::setFacadeApplication($app);
    
    s(Config::get('test'));
    s(Config::get('app.cnx'));
    
    s(Cache::get('test'));
    s(Arr::get(Cache::get('app'), 'cnx'));
    
    s(Env::get('RUN_MODE'));
    

    Output: Screen Shot 2021-09-08 at 4 50 25 PM

    opened by paxperscientiam 0
  • Suggestion for Config

    Suggestion for Config

    After much tinkering, I've come up with a way to access config data via Illuminate\Support\Facades\Config

    This uses some code from the existing Config example and uses a container (using kint just for dumping):

    <?PHP
    use Illuminate\Support\Facades\Config;
    use Illuminate\Container\Container;
    use Illuminate\Config\Repository;
    
    $config = new Repository(require(FILE_ROOT . "/config/app.php"));
    $app = new Container();
    
    $app->instance(
        'config',
        $config
    );
    
    Illuminate\Support\Facades\Facade::setFacadeApplication($app);
    s($app->get('config')->get("app"));
    s(Config::get('app'));
    

    Output: Screen Shot 2021-08-31 at 1 42 25 AM

    Current example uses a slim app, so is incompatible with the above. Would it make sense to add a separate file like "components/config/example2.php" (for instance)?

    EDIT: This may tie in some how to PR #191 ... but maybe not.

    opened by paxperscientiam 0
  • Use env() helper by invoking Dotenv\Dotenv directly

    Use env() helper by invoking Dotenv\Dotenv directly

    Hey

    I've provided an example of how to use the env() helper in conjunction with direct leverage of the Dotenv\Dotenv library. Unfortunately, the values aren't accessible with Illuminate\Support\Env; not sure what the missing bit is.

    That said, maybe it's not important. IIRC, laravel folks say to only rely on app environment variables in the config files.

    Thoughts?

    opened by paxperscientiam 1
Owner
Matt Stauffer
Matt Stauffer
The Laravel.io Community Portal.

Laravel.io This is the repository for the Laravel.io community portal. The code is entirely open source and licensed under the MIT license. We welcome

Laravel.io 2.2k Dec 23, 2022
Attendize is an open-source ticket selling and event management platform built on Laravel.

Attendize is an open-source ticketing and event management application built using the Laravel PHP framework. Attendize allows event organisers to sel

Attendize 3.6k Jan 6, 2023
Laravel e-commerce Application.

Antvel Introduction Antvel is an ecommerce project written in Laravel 5.* intended for building a friendly eStore either for startups or big companies

Antvel - Official 650 Dec 28, 2022
A Laravel publishing platform

Introduction Canvas is a fully open source package to extend your existing Laravel application and get you up-and-running with a blog in just a few mi

Todd Austin 3.1k Jan 2, 2023
Vuedo is a blog platform, built with Laravel and Vue.js.

Vuedo What is Vuedo? Vuedo is an open source project built with Laravel and Vue.js. It is a live example of how everything works together. Interested

vuedo 2.3k Dec 24, 2022
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
This is an experiment to export all RFCs from the PHP wiki into Git, including the change history for each RFC (along with the date and author of each change). This is not meant to replace the wiki.

PHP Requests for Comments (RFCs) About This repository is an experiment to export all RFCs from the PHP wiki into Git, including the change history fo

Ben Ramsey 34 Jun 20, 2022
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

The Laravel Components 2.5k Dec 27, 2022
Demo serverless applications, examples code snippets and resources for PHP

The Serverless LAMP stack Examples Code example Description AWS blog link 0.1-SimplePhpFunction A very simple implementation of a PHP Lambda function.

AWS Samples 303 Dec 20, 2022
Firebird Illuminate package for Laravel 5

laravel-firebird Please Note: This package has been abandoned by it's creator, when I created it there were no other decent laravel packages around an

Jacques van Zuydam 62 Jan 26, 2022
A Collections-only split from Laravel's Illuminate Support

Collect - Illuminate Collections Deprecated: With the separation of Illuminate's Collections package, Collect is no longer necessary ?? . We will main

Tighten 1.5k Dec 28, 2022
The Slim PHP micro framework paired with Laravel's Illuminate Database toolkit.

Slim & Eloquent The Slim PHP micro framework paired with Laravel's Illuminate Database toolkit. Getting started # Download composer curl -s https://ge

Kyle Ladd 111 Jul 23, 2022
A Collections-only split from Laravel's Illuminate Support

Collect - Illuminate Collections Deprecated: With the separation of Illuminate's Collections package, Collect is no longer necessary ?? . We will main

Tighten 1.5k Dec 30, 2022
Laravel illuminate/filesystem for webman

webman-tech/laravel-filesystem Laravel illuminate/filesystem for webman 介绍 站在巨人(laravel)的肩膀上使文件存储使用更加可靠和便捷 所有方法和配置与 laravel 几乎一模一样,因此使用方式完全参考 Laravel文

null 5 Dec 15, 2022
This package extends Illuminate to provide partitioned table creation in migrations.

Laravel Partitions for Migrations This package extends Illuminate to provide partitioned table creation in migrations for PostgreSQL. Support for othe

ORPTech 9 Oct 24, 2022
A non-blocking concurrency framework for PHP applications. 🐘

Amp is a non-blocking concurrency framework for PHP. It provides an event loop, promises and streams as a base for asynchronous programming. Promises

Amp 3.8k Jan 6, 2023
A non-blocking concurrency framework for PHP applications. 🐘

Amp is a non-blocking concurrency framework for PHP. It provides an event loop, promises and streams as a base for asynchronous programming. Promises

Amp 3.8k Jan 4, 2023
Middleware to generate access logs for each request using the Apache's access log format

Middleware to generate access logs for each request using the Apache's access log format. This middleware requires a Psr log implementation, for example monolog.

Middlewares 20 Jun 23, 2022
Foreman is a Laravel scaffolding application that automates common tasks you typically perform with each new Laravel app you create

Foreman is a Laravel scaffolding application that automates common tasks you typically perform with each new Laravel app you create. The directives you want Forman to perform are outlined in a JSON based template file.

Indatus 145 Apr 13, 2022
A laravel Livewire Dynamic Selects with multiple selects depending on each other values, with infinite levels and totally configurable.

Livewire Combobox: A dynamic selects for Laravel Livewire A Laravel Livewire multiple selects depending on each other values, with infinite levels of

Damián Aguilar 25 Oct 30, 2022