Giter VIP home page Giter VIP logo

silexstarter's Introduction

[Build Status] (https://scrutinizer-ci.com/g/xsanisty/SilexStarter/build-status/develop) [Scrutinizer Code Quality] (https://scrutinizer-ci.com/g/xsanisty/SilexStarter/?branch=develop) [Code Coverage] (https://scrutinizer-ci.com/g/xsanisty/SilexStarter/?branch=develop) [SensioLabsInsight] (https://insight.sensiolabs.com/projects/a30a66f9-8110-40c5-8a35-f3c1697dde55)

screenshot

SilexStarter

SilexStarter is a starter application built on the top of Silex framework, Laravel's Eloquent, Cartalyst Sentry, and some other third party and built in components. SilexStarter aim to help building simple application faster, it built with MVC and modular approach in mind, and comes with some basic admin module, including user manager, and module manager.

Installation

For now, the installable branch is only develop branch, you can easily install it using composer by using following command

composer create-project xsanisty/silexstarter target_dir dev-develop -s dev

once composer install is completed, you can initialize the app using following command

$cd target_dir
$./xpress app:init

Module can be developed directly inside the app/modules directory and create module on its own namespace or build it as separate composer package, module can be enabled or disabled by registering it in app/config/modules.php

Route

file : app/routes.php Route configuration can be created like normal Silex route, or using route builder using similar syntax like Laravel's route.

Silex routing style

/* the application instance is available as $app in context of route.php */

$app->get('/page', function(){
    return 'I am in a page';
});

$app->post('/save', function(){
   return 'Ok, all data is saved!';
});

/* grouping */
$app->group('prefix', function() use ($app) {
    $app->group('page', function() use ($app) {
        $app->get('index', function(){
            return 'I am in prefix/page/index';
        });
    });
});

/* resourceful controller */
$app->resource('prefix', 'SomeController');

/* route controller */
$app->controller('prefix', 'SomeController');

Laravel routing style

/* route can be built using the Route static proxy */

Route::get('/page', function(){
    return 'I am in a page';
});

Route::post('/save', function(){
   return 'Ok, all data is saved!';
});

/* grouping */
Route::group('prefix', function() {
    Route::group('page', function() {
        Route::get('index', function(){
            return 'I am in prefix/page/index';
        });
    });
});

/* resourceful controller */
Route::resource('prefix', 'SomeController');

/* route controller */
Route::controller('prefix', 'SomeController');

Controller

file: app/controllers/*

Controller basically can be any classes that reside in controllers folder, it will be registered as service when enabled, and will be properly instantiated when needed, with all dependency injected.

Assume we have PostRepository and CommentRepository, we should register it first before it can be properly injected into controller.

file: app/services/RepositoryServiceProvider.php

<?php

use Silex\Application;
use Silex\ServiceProviderInterface;

class RepositoryServiceProvider implements ServiceProviderInterface
{
    public function register(Application $app)
    {
        $app['PostRepository'] = $app->share(function (Application $app) {
            return new PostRepository
        });

        $app['CommentRepository'] = $app->share(function (Application $app) {
            return new PostRepository
        });
    }

    public function boot(Application $app)
    {

    }
}

file: app/config/services.php

<?php

return [
    'common' => [
        'RepositoryServiceProvider',
    ]
]

file: app/controllers/PostController.php

<?php

class PostController{

    protected $postRepo;
    protected $commentRepo;

    public function __construct(PostRepository $postRepo, CommentRepository $commentRepo)
    {
        $this->postRepo = $postRepo;
        $this->commentRepo = $commentRepo;
    }

    public function index(){
        return Response::view('post/index', $this->postRepo->all());
    }
}

and now, we should able to create route map to this controller

Route::get('/post', 'PostController:index');

Model

file: app/models/*

SilexStarter use Eloquent ORM as database abstraction layer, so you can extends it to create model classJeyac. The configuration of the database can be found in app/config/database.php

<?php

class Post extends Model{
    protected $table = 'posts';

    public function comments(){
        return $this->hasMany('Comment');
    }
}

View

file: app/views/*

Middleware

file: app/middlewares.php

Service Provider

file: src/Providers/*

Module

file: app/modules/*

Register module

file: app/config/modules.php

Module Provider

file: app/modules/**/ModuleProvider.php

Menu

Asset

silexstarter's People

Contributors

ikhsan017 avatar

Watchers

James Cloos avatar

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.