Loader
class Loader extends AbstractAssetsPackage
Class to manage assets paths
The class is based on three paths:
root_dir
: the package root directory (must be the directory containing thecomposer.json
file)assets_dir
: the package asssets directory related toroot_dir
document_root
: the path in the filesystem of the web assets root directory ; this is used to build all related assets paths to use in HTTP.
For these three paths, their defaults values are defined on a default package structure:
package_name/
|----------- src/
|----------- www/
$loader->root_dir = realpath(package_name)
$loader->assets_dir = www
$loader->document_root = www or the server DOCUMENT_ROOT
NOTE - These paths are stored in the object without the trailing slash.
Constants
PRESETS_NO_CONFLICT |
Flag to use to avoid throwing an exception in case of presets conflicts
|
PRESETS_CONFLICT |
Flag to use to throw exception in case of presets conflicts (default)
|
Methods
Loader protected constructor, use the class as a Singleton
Set the project root directory absolute path
Set the project's assets directory, relative to $this->_root_dir
Get the project's assets directory, relative to $this->_root_dir
Set the project's vendor directory, relative to $this->_root_dir
Get the project's vendor directory, relative to $this->_root_dir
Set the project's assets vendor directory, relative to $this->_assets_dir
Get the project's vendor directory, relative to $this->_root_dir
Get the absolute path in the package
Loader static instance constructor
Initializing a new loader populating all paths & packages
Set the document root directory
Get the document root directory
Set the package's assets database
Get the package's assets database
Get the web path for assets
Get the assets full path for a specific package
Get the web path for assets of a specific package
Test if a package exists
Get a package instance
Load and validate all packages presets in one table
Test if a preset exists
Get the package's assets database
Get a preset instance from static loader
Get a package instance from static loader
Build a web path ready to use in HTML
Find an asset file in the filesystem
Find an asset file in the filesystem of a specific package
Find an asset file in a package's path
Test if a string is a classic url or an url like //domain.ext/asset
Details
at line 148
__construct(string $root_dir = null, string $assets_dir = null, string $document_root = null, int $conflict_flag = self::PRESETS_CONFLICT)
Loader protected constructor, use the class as a Singleton
in AbstractAssetsPackage at line 112
AbstractAssetsPackage
setRootDirectory(string $path)
Set the project root directory absolute path
in AbstractAssetsPackage at line 129
string
getRootDirectory()
Get the project root directory absolute path
in AbstractAssetsPackage at line 141
AbstractAssetsPackage
setAssetsDirectory(string $path)
Set the project's assets directory, relative to $this->_root_dir
in AbstractAssetsPackage at line 159
string
getAssetsDirectory()
Get the project's assets directory, relative to $this->_root_dir
in AbstractAssetsPackage at line 171
AbstractAssetsPackage
setVendorDirectory(string $path)
Set the project's vendor directory, relative to $this->_root_dir
in AbstractAssetsPackage at line 189
string
getVendorDirectory()
Get the project's vendor directory, relative to $this->_root_dir
in AbstractAssetsPackage at line 201
AbstractAssetsPackage
setAssetsVendorDirectory(string $path)
Set the project's assets vendor directory, relative to $this->_assets_dir
in AbstractAssetsPackage at line 219
string
getAssetsVendorDirectory()
Get the project's vendor directory, relative to $this->_root_dir
in AbstractAssetsPackage at line 236
string
getFullPath(string $path, string $type = null, bool $out = false)
Get the absolute path in the package
in AbstractAssetsPackage at line 277
string
getAssetsRealPath()
Get the assets full path
in AbstractAssetsPackage at line 287
string
getVendorRealPath()
Get the assets full path
in AbstractAssetsPackage at line 297
string
getAssetsVendorRealPath()
Get the assets vendor full path
at line 128
static Loader
getInstance(string $root_dir = null, string $assets_dir = null, string $document_root = null, int $conflict_flag = self::PRESETS_CONFLICT)
Loader static instance constructor
at line 171
void
init(string $root_dir = null, string $assets_dir = null, string $document_root = null)
Initializing a new loader populating all paths & packages
at line 240
Loader
setDocumentRoot(string $path)
Set the document root directory
at line 259
string
getDocumentRoot()
Get the document root directory
at line 270
Loader
setAssetsDb(array $db)
Set the package's assets database
at line 291
array
getAssetsDb()
Get the package's assets database
at line 306
string
getAssetsWebPath()
Get the web path for assets
at line 317
string
getPackageAssetsPath(string $package_name)
Get the assets full path for a specific package
at line 330
string
getPackageAssetsWebPath(string $package_name)
Get the web path for assets of a specific package
at line 346
bool
hasPackage(string $package_name)
Test if a package exists
at line 364
AssetsPackage
getPackage(string $package_name)
Get a package instance
at line 425
void
validatePresets()
Load and validate all packages presets in one table
at line 454
bool
hasPreset(string $preset_name)
Test if a preset exists
at line 468
Preset
getPreset(string $preset_name)
Get a preset instance
at line 536
static array
getAssets()
Get the package's assets database
at line 548
static Preset
findPreset(string $preset_name)
Get a preset instance from static loader
at line 560
static AssetsPackage
findPackage(string $package_name)
Get a package instance from static loader
at line 578
static string
buildWebPath(string $path)
Build a web path ready to use in HTML
This will build a relative path related to the object $document_root
and ready-to-use
in HTML attributes. It uses the "smart resolving" feature of the Library\Helper\Filesystem
class: path is returned relative to $document_root
even if it is not in it in the
filesystem.
at line 591
static string|null
find(string $filename, string $package = null)
Find an asset file in the filesystem
at line 608
static string|null
findInPackage(string $filename, string $package)
Find an asset file in the filesystem of a specific package
at line 628
static string|null
findInPath(string $filename, string $path)
Find an asset file in a package's path
at line 643
static bool
isUrl(string $str)
Test if a string is a classic url or an url like //domain.ext/asset