2017 © Pedro Peláez
 

library slim3-skeleton

Slim starter / Slim skeleton package to boost your development with Slim framework

image

jupitern/slim3-skeleton

Slim starter / Slim skeleton package to boost your development with Slim framework

  • Wednesday, July 4, 2018
  • by jupitern
  • Repository
  • 4 Watchers
  • 18 Stars
  • 135 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 1 Open issues
  • 35 Versions
  • 13 % Grown

The README.md

Slim Framework 3 Skeleton Application (http + cli)

Use this skeleton application to quickly setup and start working on a new Slim Framework 3 application (Tested with slim 3.12). This application handles http and command line requests. This application ships with a few service providers and a session middleware out of the box. Support for container resolution and auto-wiring., (*1)

To remove a service provider comment it on config/app.php file and remove it from composer.json, update composer., (*2)

Available service providers:, (*3)

Available middleware:, (*4)

  • Session

Install the Application

Run this command from the directory in which you want to install your new Slim Framework application., (*5)

php composer.phar create-project jupitern/slim3-skeleton [my-app-name]

Replace [my-app-name] with the desired directory name for your new application. You'll want to:, (*6)

  • Point your virtual host document root to your new application's public/ directory.
  • Ensure storage/ is web writable.
  • make the necessary changes in config file config/app.php

Run it:

  1. $ cd [my-app-name]\public
  2. $ php -S localhost:8080 OR $ composer serve
  3. Browse to http://localhost:8080

Key directories

  • app: Application code (models, controllers, cli commands, handlers, middleware, service providers and others)
  • config: Configuration files like db, mail, routes...
  • lib: Other project classes like utils, business logic and framework extensions
  • storage: Log files, cache files and your raw, un-compiled assets such as LESS, SASS, or JavaScript.
  • public: The public directory contains index.php file, assets such as images, JavaScript, and CSS
  • views: Views template files.
  • vendor: Composer dependencies

Routing and dependency injection

The app class has a route resolver method that: * matches and injects params into the controller action passed as uri arguments * looks up and injects dependencies from the container by matching controller constructor / method argument class names * automatic Resolution using controller constructor / method argument types * accepts string or Response object as controller action response, (*7)

Example defining two routes for a website and backend folders:, (*8)


use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; // simple route example $app->get('/welcome/{name}', function (Request $request, Response $response, $args) { $name = $request->getAttribute('name'); $response->getBody()->write("Hello, $name"); return $response; }); // example route to resolve request to uri '/' to \App\Http\Site\Welcome::index $app->any('/', function ($request, $response, $args) use($app) { return $app->resolveRoute([\App\Http\Welcome::class, "index"], $args); }); // example calling http://localhost:8080/index.php/test/nuno with the route bellow // injects the :name param value into the method $name parameter // Other parameters in the method will be searched in the container by classname or automatically resolved // in this example the resolveRoute method will create a user instance and inject it in the controller method $app->any('/test[/{name}]', function ($request, $response, $args) use($app) { return $app->resolveRoute([\App\Http\Welcome::class, "method"], $args); }); namespace App\Http; use Jupitern\Slim3\App\Http\Controller; class Welcome extends Controller { public function method($name, \App\Model\User $user) { return get_class($user)."<br/>name = {$name}"; } }

Console usage

  • Usage: php cli.php [command-name] [method-name] [parameters...]
  • Help: php cli.php help

How to create a new command: 1. Create a class under directory app\Console in namespace App\Console 2. Your class should extend \App\Console\Command 3. create a public method with some params. 4. DONE!, (*9)

Example:, (*10)

Command class:, (*11)

namespace App\Console;

class Test extends Command
{

    public function method($a, $b='foobar')
    {
        return
            "\nEntered console command with params: \n".
            "a= {$a}\n".
            "b= {$b}\n";
    }
}

Execute the class:method from command line:, (*12)

// since param "b" is optional you can use one of the following commands

> php cli.php Test method a=foo b=bar

> php cli.php Test method a=foo

Code examples

Get application instance, (*13)

$app = \Lib\Framework\App::instance();
// or simpler using a helper function
$app = app();

Debug a variable, array or object using the debug helper function, (*14)

debug(['a', 'b', 'c']);
// or debug and exit passing true as second param
debug(['a', 'b', 'c'], true);

Read a user from db using Laravel Eloquent service provider, (*15)

$user = \App\Model\User::find(1);
echo $user->Name;

Send a email using PHPMailer service provider service named 'mail' on config file, (*16)

/* @var $mail \PHPMailer\PHPMailer\PHPMailer */
$mail = app()->resolve('mail');
$mail->addAddress('john.doe@domain.com');
$mail->Subject = "test";
$mail->Body    = "<b>test body</b>";
$mail->AltBody = "alt body";
$mail->send();

List a directory content with Flysystem service provider named 'fs_local' on config file, (*17)

$filesystem = app()->resolve('fs_local');
$contents = $filesystem->listContents(STORAGE_PATH, true);
var_dump($contents);

Write and read from session using Session Helper class, (*18)

// save user info in session
\Jupitern\Slim3\Utils\Session::set('user', ['id' => '1']);
// get user info from session
$uservar = \Jupitern\Slim3\Utils\Session::get('user');
var_dump($uservar);

Write and read from cache with Redis service provider named 'redis' on config file, (*19)

/** @var \Jupitern\Slim3\Utils\Redis $cache */
$cache = app()->resolve('redis');
$cache->set("cacheKey", "some test value");
echo $cache->get("cacheKey");

Changelog

v3.0 - moved core code to another package. - route resolution using reflection can now be switched off for performance. - config file services changed structure. - register services in container using a string instead of classnames. - code refactor and improvements., (*20)

v2.6 - Replaced Whoops and Collision packages by slashtrace that provides http and cli debug, (*21)

V2.5 - Allow for providers and middleware to be registered only for a given scope (dependent on app name) - general code improvements and error handling when developing rest api, (*22)

Roadmap

  • [ ] more service providers / separate service providers in packages
  • [ ] more code examples

Contributing

  • welcome to discuss a bugs, features and ideas.

License

jupitern/slim3-skeleton is release under the MIT license., (*23)

The Versions

04/07 2018

dev-master

9999999-dev

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

04/07 2018

2.3.0

2.3.0.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

13/04 2018

2.2.1

2.2.1.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

15/01 2018

2.2.0

2.2.0.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

14/12 2017

2.1.4

2.1.4.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

29/11 2017

2.1.3

2.1.3.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

27/11 2017

2.1.2

2.1.2.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

25/11 2017

2.1.1

2.1.1.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

23/11 2017

2.1.0

2.1.0.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api skeleton cli starter slim php framework slim starter slim php slim skeleton

15/11 2017

2.0.6

2.0.6.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton cli starter slim php framework slim starter slim php slim skeleton

10/11 2017

2.0.5

2.0.5.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

08/11 2017

2.0.4

2.0.4.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

08/11 2017

2.0.3

2.0.3.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

08/11 2017

2.0.2

2.0.2.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

08/11 2017

2.0.1

2.0.1.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

08/11 2017

2.0.0

2.0.0.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

21/09 2017

1.0.5

1.0.5.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

09/06 2017

1.0.3

1.0.3.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

09/06 2017

1.0.4

1.0.4.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

30/05 2017

1.0.2

1.0.2.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

25/05 2017

1.0.1

1.0.1.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

24/05 2017

1.0.0

1.0.0.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

05/01 2017

0.5.0

0.5.0.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

04/01 2017

0.4.3

0.4.3.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

04/01 2017

0.4.2

0.4.2.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

04/01 2017

0.4.0

0.4.0.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

04/01 2017

0.4.1

0.4.1.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

20/12 2016

0.3.3

0.3.3.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

15/12 2016

0.3.2

0.3.2.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

15/12 2016

0.3.1

0.3.1.0

Slim starter / Slim skeleton package to boost your development with Slim framework

  Sources   Download

MIT

The Requires

 

api skeleton starter slim php framework slim starter slim php slim skeleton

15/12 2016

0.3.0

0.3.0.0

Slim starter / Slim skeleton package to boost your development with Slim

  Sources   Download

MIT

The Requires

 

skeleton starter slim slimphp slim-starter slim-skeleton

14/12 2016

0.2.2

0.2.2.0

Slim starter / Slim skeleton package to boost your development with Slim

  Sources   Download

MIT

The Requires

 

skeleton starter slim slimphp slim-starter slim-skeleton

12/12 2016

0.2.1

0.2.1.0

Slim starter / Slim skeleton package to boost your development with Slim

  Sources   Download

MIT

The Requires

 

skeleton starter slim slimphp slim-starter slim-skeleton

12/12 2016

0.2.0

0.2.0.0

Slim starter / Slim skeleton package to boost your development with Slim

  Sources   Download

MIT

The Requires

 

skeleton starter slim slimphp slim-starter slim-skeleton

12/12 2016

0.1.0

0.1.0.0

Slim starter / Slim skeleton package to boost your development with Slim

  Sources   Download

MIT

The Requires

 

skeleton starter slim slimphp slim-starter slim-skeleton