itsgoingd/slim-services 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

itsgoingd/slim-services

最新稳定版本:v1.0

Composer 安装命令:

composer require itsgoingd/slim-services

包简介

Service manager for Slim compatible with Laravel packages

README 文档

README

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

"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

"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' => 'igor@no.name'
    ),
    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.

统计信息

  • 总下载量: 15.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 75
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 75
  • Watchers: 6
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固