Service manager for Slim compatible with Laravel packages

Last update: Apr 19, 2022

SlimServices

SlimServices is a service manager for the Slim PHP microframework based on Laravel 4 service providers and DI container, allowing you to use core and many third-party Laravel packages in Slim based projects.

For example, to add Eloquent ORM to your Slim app:

require 'vendor/autoload.php';

use SlimServices\ServiceManager;

$app = new Slim\Slim(array(
	// paths
	'path' => __DIR__,
	// database
    'database.fetch' => PDO::FETCH_CLASS,
    'database.default' => 'main',
    'database.connections' => array(
        'main' => array(
            'driver'    => 'mysql',
            'host'      => '127.0.0.1',
            'database'  => 'my_database',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),
    )
));

$services = new ServiceManager($app);
$services->registerServices(array(
	'Illuminate\Events\EventServiceProvider',
	'Illuminate\Database\DatabaseServiceProvider'
));

// Laravel database component is now available in Slim's DI container

$app->get('/users', function()
{
	$app->render('users.html', array(
		// Load user list using Laravel database fluent query builder
		'users' => $app->db->table('users')->where('active', 1)->get()
	));
})

$app->run();

You can find more information about service providers in the Laravel documentation.

Installation

To install the latest version simply add this to your composer.json:

"itsgoingd/slim-services": "dev-master"

Once the package is installed, you need to create a ServiceManager and register the services you'd like to use, configuration for the services is shared with the Slim instance itself:

use SlimServices\Service;

$app = new Slim(...);

$services = new ServiceManager($app);
$services->registerServices(array(
	'Illuminate\Events\EventServiceProvider',
	'Illuminate\Database\DatabaseServiceProvider',
	'Illuminate\Filesystem\FilesystemServiceProvider',
	'Illuminate\Translation\TranslationServiceProvider',
	'Illuminate\Validation\ValidationServiceProvider',
	'Mailer\MailerServiceProvider',
	'Upload\UploadServiceProvider',
	...
));

Configuration examples for some popular components:

Illuminate/Database

=2.3.0", "itsgoingd/slim-services": "dev-master", "illuminate/database": "4.1.*" }">
"require": {
    "slim/slim": ">=2.3.0",
    "itsgoingd/slim-services": "dev-master",
    "illuminate/database": "4.1.*"
}
require 'vendor/autoload.php';

use SlimServices\ServiceManager;

$app = new Slim\Slim(array(
	// paths
	'path' => __DIR__,
	// database
    'database.fetch' => PDO::FETCH_CLASS,
    'database.default' => 'main',
    'database.connections' => array(
        'main' => array(
            'driver'    => 'mysql',
            'host'      => '127.0.0.1',
            'database'  => 'my_database',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),
    )
));

$services = new ServiceManager($app);
$services->registerServices(array(
	'Illuminate\Events\EventServiceProvider',
	'Illuminate\Database\DatabaseServiceProvider'
));

$users = $app->db->table('users')->select('login')->get();

class User extends Illuminate\Database\Eloquent\Model { public $table = 'users'; }

$users = User::all();

Illuminate/Validation

=2.3.0", "itsgoingd/slim-services": "dev-master", "illuminate/validation": "4.1.*", "illuminate/filesystem": "4.1.*", "illuminate/translation": "4.1.*" }">
"require": {
    "slim/slim": ">=2.3.0",
    "itsgoingd/slim-services": "dev-master",
	"illuminate/validation": "4.1.*",
    "illuminate/filesystem": "4.1.*",
    "illuminate/translation": "4.1.*"
}
require 'vendor/autoload.php';

use SlimServices\ServiceManager;

$app = new Slim\Slim(array(
	// paths
	'path' => __DIR__,
	// app
	'app.locale' => 'en'
));

$services = new ServiceManager($app);
$services->registerServices(array(
	'Illuminate\Filesystem\FilesystemServiceProvider',
	'Illuminate\Translation\TranslationServiceProvider',
	'Illuminate\Validation\ValidationServiceProvider'
));

$validator = $app->validator->make(
    array(
        'name' => 'Igor',
        'password' => 'noname',
        'email' => '[email protected]'
    ),
    array(
        'name' => 'required',
        'password' => 'required|min:8',
        'email' => 'required|email|unique:users'
    )
);

if ($validator->fails()) { ... }

Custom service providers

You can create custom service providers simply by extending the Illuminate\Support\ServiceProvider class and registering them with the ServiceManager.

class MailerServiceProvider extends Illuminate\Support\ServiceProvider
{
	public function register()
	{
		$this->app->bindShared('mailer', function($app)
		{
			return new Mailer($app['config']);
		});
	}
}

$services->registerServices(array(
	...,
	'MailerServiceProvider'
));

$app->mailer->send(...);

Licence

Copyright (c) 2014 Miroslav Rigler

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

GitHub

https://github.com/itsgoingd/slim-services
You might also like...

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

Mar 1, 2022

Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

Apr 19, 2022

A simple Laravel service provider for easily using HTMLPurifier inside Laravel

HTMLPurifier for Laravel 5/6/7/8 A simple Laravel service provider for easily using HTMLPurifier inside Laravel. From their website: HTML Purifier is

Jun 28, 2022

🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper

🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper

🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper

Apr 2, 2022

Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration.

Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration.

Migrator Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration. Installation: To install Migrator you

Jun 28, 2022

Seo Manager Package for Laravel ( with Localization )

Seo Manager Package for Laravel ( with Localization )

Seo Manager Package for Laravel ( with Localization ) lionix/seo-manager package will provide you an interface from where you can manage all your page

Jun 27, 2022

Bring multi themes support to your Laravel application with a full-featured Themes Manager

Bring multi themes support to your Laravel application with a full-featured Themes Manager

Introduction hexadog/laravel-themes-manager is a Laravel package which was created to let you developing multi-themes Laravel application. Installatio

Jun 25, 2022

File manager for Laravel

File manager for Laravel

Laravel File Manager DEMO: Laravel File Manager Vue.js Frontend: alexusmai/vue-laravel-file-manager Documentation Laravel File Manager Docs Installati

Jun 25, 2022

Webhook Manager for Laravel Nova

Webhook Manager for Laravel Nova

Webhook Manager for Laravel Nova A Laravel Nova tool that allows users to create and manage webhooks based on Eloquent Model events. A tool for Larave

Apr 5, 2022
Comments
  • 1. laravel paginate

    $rows = Company::where('is_active', 1)->paginate(10);

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Slim Application Error The application could not run because of the following error:

    Details

    Type: ReflectionException Code: -1 Message: Class request does not exist File: /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php Line: 501 Trace #0 /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php(501): ReflectionClass->__construct('request') #1 /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php(425): Illuminate\Container\Container->build('request', Array) #2 /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php(809): Illuminate\Container\Container->make('request') #3 /Users/tuva/Sites/ticmer/vendor/illuminate/pagination/Illuminate/Pagination/PaginationServiceProvider.php(23): Illuminate\Container\Container->offsetGet('request') #4 /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php(207): Illuminate\Pagination\PaginationServiceProvider->Illuminate\Pagination{closure}(Object(TuvaServices\ServiceManager)) #5 /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php(498): Illuminate\Container\Container->Illuminate\Container{closure}(Object(TuvaServices\ServiceManager), Array) #6 /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php(425): Illuminate\Container\Container->build(Object(Closure), Array) #7 /Users/tuva/Sites/ticmer/vendor/illuminate/container/Illuminate/Container/Container.php(809): Illuminate\Container\Container->make('paginator') #8 /Users/tuva/Sites/ticmer/vendor/illuminate/database/Illuminate/Database/DatabaseManager.php(160): Illuminate\Container\Container->offsetGet('paginator') #9 [internal function]: Illuminate\Database\DatabaseManager->Illuminate\Database{closure}() #10 /Users/tuva/Sites/ticmer/vendor/illuminate/database/Illuminate/Database/Connection.php(837): call_user_func(Object(Closure)) #11 /Users/tuva/Sites/ticmer/vendor/illuminate/database/Illuminate/Database/Eloquent/Builder.php(225): Illuminate\Database\Connection->getPaginator() #12 /Users/tuva/Sites/ticmer/app/routes/site.php(101): Illuminate\Database\Eloquent\Builder->paginate(2) #13 [internal function]: {closure}() #14 /Users/tuva/Sites/ticmer/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array) #15 /Users/tuva/Sites/ticmer/vendor/slim/slim/Slim/Slim.php(1338): Slim\Route->dispatch() #16 /Users/tuva/Sites/ticmer/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim->call() #17 /Users/tuva/Sites/ticmer/vendor/slim/slim/Slim/Middleware/MethodOverride.php(92): Slim\Middleware\Flash->call() #18 /Users/tuva/Sites/ticmer/vendor/slim/slim/Slim/Middleware/SessionCookie.php(110): Slim\Middleware\MethodOverride->call() #19 /Users/tuva/Sites/ticmer/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\SessionCookie->call() #20 /Users/tuva/Sites/ticmer/vendor/slim/slim/Slim/Slim.php(1283): Slim\Middleware\PrettyExceptions->call() #21 /Users/tuva/Sites/ticmer/index.php(97): Slim\Slim->run() #22 {main}

    Reviewed by tuvaergun at 2014-12-30 15:43
A laravel service provider for the netsuite-php library service

netsuite-laravel A PHP supplemental package to the ryanwinchester/netsuite-php package to add the NetSuite service client to the service container of

Jun 2, 2022
An HTTP Interop compatible middleware dispatcher in Equip

An HTTP Interop compatible middleware dispatcher in Equip. Attempts to be PSR-1, PSR-2, PSR-4, PSR-7, and PSR-15 compliant.

Sep 1, 2021
Simple PSR-7 compatible response sender

Simple PSR-7 compatible response sender

Mar 6, 2022
📦 Adds Laravel Packages Support to Lumen and Vendor Publish Artisan Command.
📦 Adds Laravel Packages Support to Lumen and Vendor Publish Artisan Command.

Laravel Package Support for Lumen: Makes Lumen compatible with Laravel Packages. You can use any Laravel Packages in Lumen by installing Larasupport Package.

May 19, 2022
A package for Laravel to perform basic git commands on locally integrated packages.

A package for Laravel to perform basic git commands on locally integrated development packages. If working within multiple local development packages or repositories at once this package is meant to ease the burden of navigating to each individual repository to perform basic git commands.

Sep 30, 2021
Watch your Laravel app for unwanted changes when working with third-party packages.
Watch your Laravel app for unwanted changes when working with third-party packages.

Project Secure This package installs a Composer plugin that reports unwanted changes to your Laravel project code after installing or updating a third

Nov 3, 2021
Tools for creating Laravel packages
Tools for creating Laravel packages

Tools for creating Laravel packages This package contains a PackageServiceProvider that you can use in your packages to easily register config files,

Jun 26, 2022
Allow your model to record the creation, update and deletion of user fingerprints in laravel packages

This laravel package will allow your models to record the the created, updated and deleted by User FingerPrints

Mar 11, 2022
Collection of agnostic PHP Functions and helpers with zero dependencies to use as foundation in packages and other project

Collection of agnostic PHP Functions and helpers This package provides a lot of very usefull agnostic helpers to use as foundation in packages and oth

Feb 12, 2022
Composer plugin for cleaning up unused files from packages.

Composer Cleanup Plugin Remove tests & documentation from the vendor dir. Based on laravel-vendor-cleanup but implemented as a Composer Plugin instead

May 25, 2022