mindedge/blade

This package is abandoned and no longer maintained. The author suggests using the mindedge/ioc package instead.
There is no license information available for the latest version (3.0.0) of this package.

A standalone blade package that implementents a mini IoC container, and binds Illiminate\view to it

3.0.0 2019-11-08 21:11 UTC

This package is auto-updated.

Last update: 2019-11-15 14:18:43 UTC


README

Latest Version Build Status Coverage Status

Mindedge Blade

Composer package that provides Laravels IOC Container, which any laravel service can be bound to. This package currently provides the following services out of the box:

  1. Illuminate\view - Github Link, Illuminate Api Documentation

    This is the service thats provides the blade engine.

  2. Illuminate\config - Github Link, Illuminate Api Documentation

    This is the service that allows services to have dedicated, easy to understand configuration files.

  3. Illuminate\database - Github Link, Illuminate Api Documentation

This is the service that provides database services such as Eloquent.

The package is now hosted on packagist, which means adding the repository array is not longer nessisary.

https://packagist.org/packages/mindedge/blade

Installation

You can use the below require statement from the command line in the root directory (assuming a composer.json already exists):

composer require mindedge/blade

Alternativly, simply add to existing dependency to "require" object in composer.json,

"require": {
    "mindedge/blade": "^2.0.0"
}

And then run

composer install

Configuration:

Within the root directory of of your app, create four directories. I have used the "ROOTDIR" to denote the application root.

  1. ROOTDIR/bootrap
  2. ROOTDIR/config
  3. ROOTDIR/cache
  4. ROOTDIR/views

Note: the 'views' directory will correspond to wherever your application holds its presentation layer files and is configurable. You may name/change the views directory to whatever makes sense for your application.

You should wind up with something like this:

|...
|
|-config
|-boostrap
|-cache
|-views
|
|...

In the newly crated boostrap directory, create a single file named app.php, with the below conents.

require_once __DIR__.'/../vendor/autoload.php';

use  Mindedge\Blade\Application;

$app = new Application(
    dirname(__DIR__)
);

$app->withFacades();

//$app->withEloquent();



//Nothing Below These Two Lines!
$app->boot();

return $app;

Note:
If you do not plan on using the view, database, or config facades, you may comment '$app->withFacades out'.
To use eloquent, Simply uncomment '$app->withEloquent'. If using you plan on using Models, make sure to add a psr4 entry in your composer.json to thier location.

This example shows the autoload script being included, but as long as vendor/autoload.php is included somewhere in the project thats globally accessable, thats a fine approach as well.

In the newly created config directory, create a single file named view.php, and place the following starter config:

<?php

return [

    'paths' => [
        './views'
    ],

    'compiled' => './cache',

];

This config file configures the View library (Blade) and contains an array with two keys.

  1. 'paths' - Represents where the Illuminate\view service should look for files. Accepted file types for this directory are .php and .blade.php. You may add as my locations to the paths array as you like.

  2. 'compiled' - Represents where the compiled/resolved views should go. If the a given file hasnt changed, View will skip the complication step and read the compiled contents of the corresponding file from this folder. Make sure this folder is writable by the application/web user.

Add another config file, for the Database library (including eloquent). Inside the config directory create a single file named database.php, and place the following starter config:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer body of commands than a typical key-value system
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => 'predis',

        'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
        ],

        'cache' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_CACHE_DB', 1),
        ],

    ],

];

All database configuration values should be defined in .env files, with a localhost default backup defined in the config file if nessisary. More information reguarding configuration can be found on the Official Laravel Docs Site

Assuming all above steps were followed correctly, you should have a directory structure that looks something simliar to this:

|...
|
|-config
|   |
|   view.php
|   database.php
|-boostrap
|   |
|   app.php
|-cache
|-views
|   |
|   welcome.blade.php
|
|...

Include boostrap/app.php in you applications entry point, somewhere thats is globally included or autoloaded, and uou are now ready to use all three services this package provides.

For further help and documenation, see the below links:

The Laravel Blade Docs.

The Laravel Database Docs

Additional Services

  1. Service Providers - This package allows you to register additional services and bind them into the IoC container via a Provider. To register a service, call the register method in the bootstrap/app file. The service class file, and the service provider file must live in a location that is psr4 autoloaded.
//boostrap/app.php 

$app->register('Acme\Company\AcmeServiceProvider');

  1. Facades - If you've created a facade for you're own service, or want to register the facade that came with a different package, you may doing so by passing the references into the 'withFacades' method. The class you are registering a facade for must live in a directory that is psr4 autoloaded.
//bootstrap/app.php

$app->withFacades(true, ['Acme\Company\AcmeService' => 'AcmeService']);
  1. Config Files - If you've created a custom service, and want to use a config file, or are using a 3rd party package that uses config file, you may create and register it with the application. In your config directory, create or import the config file. To register the config with the application, use the configure method.
//bootstrap/app.php

$app->configure('name_of_config_file');