PHP code example of itsgoingd / slim-services

1. Go to this page and download the library: Download itsgoingd/slim-services library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

itsgoingd / slim-services example snippets




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();

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',
	...
));



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();



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' => '

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(...);