PHP code example of nathanburkett / ecosystem

1. Go to this page and download the library: Download nathanburkett/ecosystem 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/ */

    

nathanburkett / ecosystem example snippets


'providers' => [

    ...

	NathanBurkett\Ecosystem\Providers\EcosystemServiceProvider::class,
]

'aliases' => [

    ...

    'Ecosystem' => NathanBurkett\Ecosystem\Facades\Ecosystem::class,



namespace App\Library\Ecosystems;

use NathanBurkett\Ecosystem\Contracts\AssetCollectionContract;
use NathanBurkett\Ecosystem\Entities\AbstractEcosystem as Ecosystem;

class StandardEcosystem extends Ecosystem implements AssetCollectionContract
{
    /**
     * Default StandardEcosystem head scripts
     * @return array
     */
    final public function defaultHeadScripts()
    {
        return [
            '' => ['src' => '']
        ];
    }

    /**
    * Default StandardEcosystem stylesheets
    * @return array
    */
    final public function defaultStylesheets()
    {
        return [
            '' => ['href' => '']
        ];
    }

    /**
    * Default StandardEcosystem footer scripts
    * @return array
    */
    final public function defaultFooterScripts()
    {
        return [
            '' => ['src' => '']
        ];
    }
}


    final public function defaultHeadScripts()
    {
        return [
            'yahoo' => ['src' => '/yahoo.js'],
            'wahoo' => ['src' => '/wahoo.js'],
            'yippee' => ['src' => '/yippee.js']
        ];
    }

    Ecosystem::getHeadScripts();

Route::group(['middleware' => 'ecosystem', 'ecosystem' => 'App\Library\Ecosystems\StandardEcosystem'], function() {
    Route::get('/', 'IndexController@index');
});

Route::group(['middleware' => 'ecosystem', 'ecosystem' => 'App\Library\Ecosystems\StandardEcosystem'], function () {
     // NewStandardEcosystem would be used for the '/' route
    Route::get('/', ['middleware' => 'ecosystem', 'ecosystem' => 'App\Library\Ecosystems\NewStandardEcosystem', 'uses' => 'IndexController@index']);
});



namespace App\Http\Controllers;

use Ecosystem;
// ...

class IndexController extends Controller
{
    public function index() {
        Ecosystem::addScriptToHead('blammo', ['src' => '/blammo.js']);
    }
}

function addScriptToHead($name, $attr = array(), $before = null)

Ecosystem::addScriptToHead('blammo', ['src' => '/blammo.js'], 'yippee');

Ecosystem::getHeadScripts();

Ecosystem::getStylesheets();

Ecosystem::getFooterScripts();



namespace App\Http\Controllers;

// import the facade
use Ecosystem;

// ...

Ecosystem::addHeadScript($name, $attr = array(), $before = null);

Ecosystem::addStylesheet($name, $attr = array(), $before = null);

Ecosystem::addFooterScript($name, $attr = array(), $before = null);