Question

I'm thinking about making a stripped-down version of Laravel that can be used as a micro-framework, kinda like the Silex of Symfony world.

I guess i need to use the Illuminate\Routing component of Laravel (available via Packagist) and make a new Router instance and then call ->dispatch on the router with a Request object but i'm not quite sure if that's the right way to do it.

I'd appreciate your suggestions/solution.

Was it helpful?

Solution

This Mohammad Gufran's blog post entitled "DRIVE YOUR APPLICATION WITH ILLUMINATE ROUTER" could give you a preview of what could be done.

To sum up:

  1. Initialize your project using Composer.
  2. Define the dependencies, namely: "illuminate/routing": "4.1.*" and "illuminate/events": "4.1.*".
  3. Create the "index.php" and "routes.php" files as suggested.

Et voilà!

Excerpt from routes.php:

$app['router']->get('/', function() {
    // Because 'Hello, World!' is too mainstream
    return 'Are you looking for me ?';
});

OTHER TIPS

Lumen "The stunningly fast micro-framework by Laravel" came to light.

Excerpt:

<?php

/**
 * Reimagine what you expect...
 */
$app->get('/', function() {
    return view('lumen');
});

/**
 * From your micro-framework...
 */
$app->post('framework/{id}', function($framework) {

    $this->dispatch(new Energy($framework));
});

Well, in order to make "stripped" version of Laravel you will have to dig deeper. Laravel is made of couple of proven architectural and design patterns.

Inside we can find:

  • Service oriented architecture in the form of Service Providers

  • Of course client/server implementation in the form of extending Symfony HTTP components

  • Clever usage of Event driven design

  • Communication with app through CLI commands

  • MVC specific implementation with Blade templating and Eloquent ORM in the DB layer.

  • Router as standalone unit.

  • Levereging Composer package capabilities.

And finally, in Laravel,everything is connected together with custom Application layer. I am fascinated with Laravel design. There is no framework that taught me more. So, to answer you question - it is possible to create your version of Laravel, but better solution is to accept what is Laravel offering, join community and improve it with you own ideas.

Laravel released Lumen, the official micro-framework for Laravel. It uses nikic/fast-route for routing instead of Symfony's Routing component for better performance.

Actually Laravel uses Symfony components (along with others) and the HTTP Foundation is built on Symfony HTTP Foundation and router is also from Symfony.

So, instead of digging into Laravel, check the Symfony components and you may easily build a micro framework using Symfony components (utilizing the composer).

For building the Foundation you may need these components:

  1. HttpFoundation
  2. Routing
  3. HttpKernel

Read the manual, it's easy and you can make it easily and also follow the framework's source that used Symfony components to get an idea how to use these components.

Have a look Micro Version of Laravel Framework here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top