GithubHelp home page GithubHelp logo

torch's Introduction

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)/¯

torch's People

Contributors

akenroberts avatar angelov avatar bangjelkoski avatar braunson avatar carousel avatar dead23angel avatar gummibeer avatar hskrasek avatar jamescarlos avatar jonahgeorge avatar jordonbrill avatar jwalton512 avatar lepidosteus avatar lexdubyna avatar mattstauffer avatar maxbublik avatar mloberg avatar rdelorier avatar reinink avatar robinmalfait avatar rohiri avatar rubemlrm avatar silentworks avatar spamoom avatar stefanstifter avatar stephanebour avatar tunr avatar wadesherman avatar waknauss avatar whyounes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

torch's Issues

Small question

Trying to integrate some laravel components into a project of mine.

Is there a way I can use Input::all() & Input::get() in that project?

Thanks

Laravel 5.4 Queue

Hi!

I just want to ask, is it possible to use Laravel 5.4 Queue component in a standalone application? I need it to be 5.4 because the target project still uses PHP 5.6 and there's no upgrade in sight in the near future.

Named Routes

How to use and echo named routes? In routing component.

Plans to add Socialite?

That one seems very handy, given its ease of use in Laravel itself. There are alternatives, but Socialite has been by far the most painless to implement for me.

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.

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):

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?

Update all components for 6.0

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. 1. Leave a comment in that issue showing you'll be pulling this task.
  2. Update the composer.json references for this component to use the Illuminate component "~6.0"
  3. 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
  4. 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
  5. If it all works, PR it! If you get stuck, PR where you are with notes about what got stuck

Database connection in Queue Component

Hello,

I'm trying to add a database connection to Queue component. Something like:

$capsule = new Capsule;
$capsule->addConnection([
    'driver' =>'mysql',
    'host' => $dbhost,
    'database' => $dbname,
    'username' => $dbuname,
    'password' => $dbpass,
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => $prefix."_",
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();


$container->instance("capsule", $capsule);

// Sistema de colas
$queue = new Queue();

$queue->addConnection([
    'driver' => 'sync',
]);
$queue->addConnection([
    'driver' => 'database',
    'table' => 'jobs',
    'queue' => 'default',
    'connection' => 'default',
    'host'      => 'localhost',
], 'database');

$manager = $queue->getQueueManager();
$container['queue'] = $manager;
$connection = Capsule::schema()->getConnection();
$resolver = new \Illuminate\Database\ConnectionResolver(['default' => $connection]);
$manager->addConnector('database', function () use ($resolver) {
    return new DatabaseConnector($resolver);
});
$queue->setAsGlobal();

I created the table like Laravel does. I'm trying to do the same as Laravel, that is,
WorklistOrderJob :: dispatch ($order);
with this code

$orden = Orden::where('idorden', 2015111100000000054)->first();
$queue->connection('database')->push('App\\Jobs\\WorklistOrderJob', $orden);

Where Orden is a Eloquent Model.

My goal is to insert in the database the instance of the model so another application in Laravel consumes the model inserted in the Jobs table.
I can see the model in the database but when I call

 php artisan queue:work --once

an error appears "Call to undefined method fire".

When I add fire method to the Job the database entrance is procesed.

public function fire()
    {
        $this->handle();
    }

Why fire thas not exists?
Laravel is in version 5.7 and I'm using Torch 5.5.
Incompatibilty problem?
Is it correct what I am saying?

Any suggestions or comments are welcomed.

Thanks in advance

database component

Thanks for your sharing.

For database component,
In Encapsulator::init() function, self::$conn should be assigned
self::$conn = new static;

Routing - Redirecting

In Laravel redirecting in your controller was a huge time saver. Your code example does not include this feature. Exploring the vendor code it looks like redirecting is included in the package. The question is how to do that?

Laravel command for redirecting:
return redirect()->route('products.index');

After playing around a bit with your code im completely lost on how to go about using the redirect feature.
Is this possible with your code?

Eloquent and softDeletes

Hello,

Eloquent works for me in 5.1, but when I change composer.json to use 5.2 tree, I get :

BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::onlyTrashed()

Any idea what could be wrong?

pagination rendering not working with "illuminate/pagination": "^5.6"

Hi. Could you please confirm that pagination rendering is not working in version 5.6 ("illuminate/pagination": "^5.6")

I got this error

Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /var/www/html/tms/vendor/illuminate/pagination/AbstractPaginator.php on line 428

Fatal error: Uncaught Error: Call to a member function make() on null in /var/www/html/tms/vendor/illuminate/pagination/Paginator.php:108 Stack trace: #0 /var/www/html/tms/test.php(41): Illuminate\Pagination\Paginator->render() #1 {main} thrown in /var/www/html/tms/vendor/illuminate/pagination/Paginator.php on line 108

Here is composer.json


{
    "require": {
        "illuminate/database": "^5.6",
        "illuminate/pagination": "^5.6",
        "illuminate/contracts": "5.6.*",
        "illuminate/support": "5.6.*",
        "illuminate/container": "^5.6",
        "illuminate/view": "^5.6"
    }
}

And here is code;

<?php
require_once __DIR__ . '/vendor/autoload.php';

// Populate items
$items = array_map(function ($value) {
    return [
        'name' => 'Blog post #' . $value,
        'url' => '/post/' . $value,
    ];
}, range(1,1000));

// Get current page from query string
$currentPage  = isset($_GET['page']) ? (int) $_GET['page'] : 1;

// Items per page
$perPage      = 10;

// Get current items calculated with per page and current page
$currentItems = array_slice($items, $perPage * ($currentPage - 1), $perPage);

// Create paginator
$paginator = new Illuminate\Pagination\Paginator($items, 10, $currentPage);
?>
<html>
<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<body>

<div class="container">
    <div class="row">
        <div class="col-xs-12">
            <h1>Blog posts - page <?=$paginator->currentPage()?></h1>

            <?php foreach ($paginator->items() as $blogPost) { ?>
                <a href="<?=$blogPost['url']?>"><h3><?=$blogPost['name']?></h3></a>
            <?php } ?>

            <?=$paginator->render()?>
        </div>
    </div>
</div>

</body>
</html>

[Proposal] Archive 4.2 to a separate branch (linked and considered a first-class citizen) and make master deal with 5.1

Illuminate/Laravel 5.1 is LTS, so it's the perfect candidate for the next step of this project; 4.3+ rely more heavily on HttpFoundation and middleware than 4.2 and before had, which is why this project has paused at 4.2 for now.

I think it's time, and have been encouraged in this direction by friends, to pursue a 5.1 version of this that is comfortable with explicitly requiring HTTPFoundation.

Queue artisan:listen

Hi,

I have attached and working with sync driver in my project, but what if we want to work with beanstalkd driver ??

How can I run artisan command outside Laravel ??

I have to use artisan:listen, I think it need for driver iron.io too or amazon ??

I culdn't figure it out to use the artisan:listen from outside of Laravel ..

Regards,

how to get config value from multiple config file at a time

I dont want to get config value from different file by creating multiple instance of illuminate \config.

// Init

For database :

 $config = new Repository(require $configPath . 'Db.php');
 // Get config using the get method

for Cache:

// Init
$CacheConfig = new Repository(require $configPath . 'cache.php');

How can i get config value from multiple file just in $config array

and how to add them to container to use with laravel components blade or cache as configuration

Resolving container

The document describes a method of 3 Resolving.
$fooBar = $this->app->make('FooBar');
$fooBar = $this->app['FooBar'];
and

<?php

namespace App\Http\Controllers;

use App\Users\Repository as UserRepository;

class UserController extends Controller
{
    /**
     * The user repository instance.
     */
    protected $users;

    /**
     * Create a new controller instance.
     *
     * @param  UserRepository  $users
     * @return void
     */
    public function __construct(UserRepository $users)
    {
        $this->users = $users;
    }
}

the first two methods work well in your example the use of the container without laravel. But a third way I did not get to use the error

Catchable fatal error: Argument 1 passed to ClassName::__construct() must be an instance of Template, none given, called in /var/www/localhost/test/index.php on line 21 and defined in /var/www/localhost/test/index.php on line 15

my code

<?php

require_once 'vendor/autoload.php';
require_once 'libraries/Template.php';

// Create new IoC Container instance
$container = new Illuminate\Container\Container;

// Bind a "template" class to the container
$container->bind('Template', 'Acme\Template');

class ClassName
{

    function __construct(Template $template)
    {
        var_dump($template);
    }
}

$class = new ClassName();

why is that?

Add Global Middleware concept to middleware component

I just had to setup global middleware (which is run on every request, not just specific routes) for something I work on and thought I'd share what I did. Sorry I don't have it in me for a PR at this point. The primary changes:

  • add use ... Pipeline
  • extract new Container into it's own variable
  • add the $globalMiddleware array
  • change the $response = $router->dispatch($request); line to use Pipeline to send the request through the middleware before dispatching through the router (based on https://github.com/illuminate/routing/blob/5.1/Router.php#L695)

Here is the reworked index.php. Note that I haven't tested this specific code, but it should be enough to get someone started in the right direction.

<?php

/**
 * Illuminate/Routing
 *
 * @source https://github.com/illuminate/routing
 * @contributor https://github.com/dead23angel
 * @contributor Matt Stauffer
 */

require_once 'vendor/autoload.php';

use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Routing\Pipeline;

// Using Illuminate/Events/Dispatcher here (not required); any implementation of
// Illuminate/Contracts/Event/Dispatcher is acceptable
$container = new Container;
$events = new Dispatcher($container);

// Create the router instance
$router = new Router($events);

// Global middlewares
$globalMiddleware = [
  // maybe something like \App\Middleware\StartSession::class
];

// Array middlewares
$routeMiddleware = [
    'auth' => \App\Middleware\Authenticate::class,
    'guest' => \App\Middleware\RedirectIfAuthenticated::class,
];

// Load middlewares to router
foreach ($routeMiddleware as $key => $middleware) {
    $router->middleware($key, $middleware);
}

// Load the routes
require_once 'routes.php';

// Create a request from server variables
$request = Request::capture();

// Dispatch the request through the router
$response = (new Pipeline($container))
                    ->send($request)
                    ->through($globalMiddleware)
                    ->then(function ($request) use ($router) {
                        return $router->dispatch($request);
                    });

// Send the response back to the browser
$response->send();

[Question]

Can you also provide some files about events?

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 👍

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?

Component facades/alias?

I'd like to use the Cache facade with the Cache component. So I can use:

Cache::get(...);

Instead of:

$cache->get(...);

It's also be nice to use the DB facade for the database component. Any idea how to set these up?

Set the request session

Hello,

I'm trying to flash the request variables. Something like

$request->flash();
Previously in my code I created the $request like
$request = Illuminate\Http\Request::createFromGlobals();
The error is:
Fatal error: Uncaught exception 'RuntimeException' with message 'Session store not set on request.'

I create the session object following the instructions in the page:

https://github.com/mattstauffer/Torch/blob/master/components/session/index.php

The questión is.

How can assign the session to the request?

The idea is to use the variables back to fill the input fill in a form in case of error.

Thanks and best regards

CacheManager needs Application

CacheManager on 5.5 needs Application instance and your example gave Container instance.
For me its not working.
Any help?

Scheduler component?

Hello,

What about a Task Scheduling component? As I see the task scheduling is in the Kernel of Laravel (ConsoleKernel). Needs the task scheduling component being so tied to the core?

Best regards

Error with Pagination

Always` getting error with pagination if i used links() or render();
Fatal error: Uncaught Error: Call to a member function make() on null in \vendor\illuminate\pagination\Paginator.php:127

Here is code:

$allItems = DB::table('products);
$allProductsCount = get_allItems()::get()->count();
$currentPage  = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$perPage      = 10;
$currentItems = array_slice($allItems, $perPage * ($currentPage - 1), $perPage);
$paginator = new Illuminate\Pagination\Paginator($allItems, 10, $currentPage);
echo $paginator->links();

View / Template Example

Hey @mattstauffer

awesome collection, really thanks for this.
Currently i am struggling to get a working view/template engine.
I tried it with twig but i run into several errors.

Do you have maybe a good example for twig or blade / how to use this in a legacy app?

Html and Form components?

How can we setup and use the Html and Form components in these standalone packages? I've included the "laravelcollective/html" in my composer.json file, but I'm not sure how to bring them in and make them usable in my views. Any idea how to do it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.