public function init($root_dir = null, $assets_dir = null, $document_root = null)
    {
        try {
            $this->setRootDirectory(!is_null($root_dir) ? $root_dir : __DIR__.'/../../../../../');

            $composer = $this->getRootDirectory() . '/' . Config::getInternal('composer-db');
            $vendor_dir = Config::get('vendor-dir');
            if (file_exists($composer)) {
                $json_package = json_decode(file_get_contents($composer), true);
                if (isset($json_package['config']) && isset($json_package['config']['vendor-dir'])) {
                    $vendor_dir = $json_package['config']['vendor-dir'];
                }
            } else {
                throw new \Exception(
                    sprintf('Composer json "%s" not found!', $composer)
                );
            }
            $this->setVendorDirectory($vendor_dir);

            $extra = isset($json_package['extra']) ? $json_package['extra'] : array();
            if (isset($extra['assets-config-class'])) {
                Config::load($extra['assets-config-class']);
            }
            if (!empty($extra)) {
                Config::overload($extra);
            }

            $assets_db_filename = isset($extra['assets-db-filename']) ? $extra['assets-db-filename'] : Config::get('assets-db-filename');
            $db_file = $this->getRootDirectory() . '/' . $this->getVendorDirectory() . '/' . $assets_db_filename;
            if (file_exists($db_file)) {
                $json_assets = json_decode(file_get_contents($db_file), true);
                $this
                    ->setAssetsDirectory(
                        !is_null($assets_dir) ? $assets_dir : (
                            isset($json_assets['assets_dir']) ? $json_assets['assets_dir'] : Config::get('assets-dir')
                        )
                    )
                    ->setAssetsVendorDirectory(
                        isset($json_assets['assets_vendor_dir']) ? $json_assets['assets_vendor_dir'] : Config::get('assets-vendor-dir')
                    )
                    ->setDocumentRoot(
                        !is_null($document_root) ? $document_root : (
                            isset($json_assets['document_root']) ? $json_assets['document_root'] : Config::get('document-root')
                        )
                    )
                    ->setAssetsDb(!empty($json_assets['packages']) ? $json_assets['packages'] : array());
            } else {
                throw new \Exception(
                    sprintf('Assets json DB "%s" not found!', $db_file)
                );
            }

            $this->validatePresets();
        } catch (\Exception $e) {
            throw $e;
        }
    }
public function init($root_dir = null, $assets_dir = null, $document_root = null)
    {
        try {
            $this->setRootDirectory(!is_null($root_dir) ? $root_dir : __DIR__.'/../../../../../');

            $composer = $this->getRootDirectory() . '/' . Config::getInternal('composer-db');
            $vendor_dir = Config::get('vendor-dir');
            if (file_exists($composer)) {
                $json_package = json_decode(file_get_contents($composer), true);
                if (isset($json_package['config']) && isset($json_package['config']['vendor-dir'])) {
                    $vendor_dir = $json_package['config']['vendor-dir'];
                }
            } else {
                throw new \Exception(
                    sprintf('Composer json "%s" not found!', $composer)
                );
            }
            $this->setVendorDirectory($vendor_dir);

            $extra = isset($json_package['extra']) ? $json_package['extra'] : array();
            if (isset($extra['assets-config-class'])) {
                Config::load($extra['assets-config-class']);
            }
            if (!empty($extra)) {
                Config::overload($extra);
            }

            $assets_db_filename = isset($extra['assets-db-filename']) ? $extra['assets-db-filename'] : Config::get('assets-db-filename');
            $db_file = $this->getRootDirectory() . '/' . $this->getVendorDirectory() . '/' . $assets_db_filename;
            if (file_exists($db_file)) {
                $json_assets = json_decode(file_get_contents($db_file), true);
                $this
                    ->setAssetsDirectory(
                        !is_null($assets_dir) ? $assets_dir : (
                            isset($json_assets['assets_dir']) ? $json_assets['assets_dir'] : Config::get('assets-dir')
                        )
                    )
                    ->setAssetsVendorDirectory(
                        isset($json_assets['assets_vendor_dir']) ? $json_assets['assets_vendor_dir'] : Config::get('assets-vendor-dir')
                    )
                    ->setDocumentRoot(
                        !is_null($document_root) ? $document_root : (
                            isset($json_assets['document_root']) ? $json_assets['document_root'] : Config::get('document-root')
                        )
                    )
                    ->setAssetsDb(!empty($json_assets['packages']) ? $json_assets['packages'] : array());
            } else {
                throw new \Exception(
                    sprintf('Assets json DB "%s" not found!', $db_file)
                );
            }

            $this->validatePresets();
        } catch (\Exception $e) {
            throw $e;
        }
    }
public function init ( $ root_dir = null , $ assets_dir = null , $ document_root = null ) { try { $ this -> setRootDirectory ( ! is_null ( $ root_dir ) ? $ root_dir : __DIR__ . '/../../../../../' ) ; $ composer = $ this -> getRootDirectory ( ) . '/' . Config :: getInternal ( 'composer-db' ) ; $ vendor_dir = Config :: get ( 'vendor-dir' ) ; if ( file_exists ( $ composer ) ) { $ json_package = json_decode ( file_get_contents ( $ composer ) , true ) ; if ( isset ( $ json_package [ 'config' ] ) && isset ( $ json_package [ 'config' ] [ 'vendor-dir' ] ) ) { $ vendor_dir = $ json_package [ 'config' ] [ 'vendor-dir' ] ; } } else { throw new \ Exception ( sprintf ( 'Composer json "%s" not found!' , $ composer ) ) ; } $ this -> setVendorDirectory ( $ vendor_dir ) ; $ extra = isset ( $ json_package [ 'extra' ] ) ? $ json_package [ 'extra' ] : array ( ) ; if ( isset ( $ extra [ 'assets-config-class' ] ) ) { Config :: load ( $ extra [ 'assets-config-class' ] ) ; } if ( ! empty ( $ extra ) ) { Config :: overload ( $ extra ) ; } $ assets_db_filename = isset ( $ extra [ 'assets-db-filename' ] ) ? $ extra [ 'assets-db-filename' ] : Config :: get ( 'assets-db-filename' ) ; $ db_file = $ this -> getRootDirectory ( ) . '/' . $ this -> getVendorDirectory ( ) . '/' . $ assets_db_filename ; if ( file_exists ( $ db_file ) ) { $ json_assets = json_decode ( file_get_contents ( $ db_file ) , true ) ; $ this -> setAssetsDirectory ( ! is_null ( $ assets_dir ) ? $ assets_dir : ( isset ( $ json_assets [ 'assets_dir' ] ) ? $ json_assets [ 'assets_dir' ] : Config :: get ( 'assets-dir' ) ) ) -> setAssetsVendorDirectory ( isset ( $ json_assets [ 'assets_vendor_dir' ] ) ? $ json_assets [ 'assets_vendor_dir' ] : Config :: get ( 'assets-vendor-dir' ) ) -> setDocumentRoot ( ! is_null ( $ document_root ) ? $ document_root : ( isset ( $ json_assets [ 'document_root' ] ) ? $ json_assets [ 'document_root' ] : Config :: get ( 'document-root' ) ) ) -> setAssetsDb ( ! empty ( $ json_assets [ 'packages' ] ) ? $ json_assets [ 'packages' ] : array ( ) ) ; } else { throw new \ Exception ( sprintf ( 'Assets json DB "%s" not found!' , $ db_file ) ) ; } $ this -> validatePresets ( ) ; } catch ( \ Exception $ e ) { throw $ e ; } }
Initializing a new loader populating all paths & packages

@param   string  $root_dir       The project package root directory
@param   string  $assets_dir     The project package assets directory, related from `$root_dir`
@param   string  $document_root  The project assets root directory to build web accessible assets paths
@return  void
@throws  \Exception : any caught exception
@throws  \Exception if the package's `ASSETS_DB_FILENAME` was not found
Initializing a new loader populating all paths & packages