Asset manager.
Constructor.
NULL
public function __construct()
{
// Nothing here
}
Returns the instance of the chosen asset group.
| Type | Description |
|---|---|
| string | Group name |
mako\Assets
public static function group($name = 'default')
{
if(!isset(static::$groups[$name]))
{
static::$groups[$name] = new static();
}
return static::$groups[$name];
}
Returns the path or URL of the assets.
string
public static function location()
{
static $location;
if($location === null)
{
$location = Config::get('mako.asset_location');
}
return $location;
}
Add an asset.
| Type | Description |
|---|---|
| string | Asset name |
| string | Asset source |
| array | (optional) Asset attributes |
NULL
protected function add($name, $source, array $attributes = array())
{
// Prefix source with asset location if it's not a URL
if(strpos($source, '://') === false)
{
$source = static::location() . $source;
}
if(pathinfo(strtok($source, '?'), PATHINFO_EXTENSION) === 'css')
{
!isset($attributes['media']) && $attributes['media'] = 'all';
defined('MAKO_XHTML') && $attributes['type'] = 'text/css';
$this->css[$name] = array('href' => $source, 'rel' => 'stylesheet') + $attributes;
}
else
{
defined('MAKO_XHTML') && $attributes['type'] = 'text/javascript';
$this->js[$name] = array('src' => $source) + $attributes;
}
}
Get one or all CSS assets.
| Type | Description |
|---|---|
| string | (optional) Asset name |
string
protected function css($name = null)
{
if($name === null)
{
$css = array();
foreach($this->css as $key => $value)
{
$css[] = $this->css($key);
}
return implode("\n", $css);
}
if(!isset($this->css[$name]))
{
return null;
}
return HTML::tag('link', $this->css[$name]);
}
Get one or all JavaScript assets.
| Type | Description |
|---|---|
| string | (optional) Asset name |
string
protected function js($name = null)
{
if($name === null)
{
$js = array();
foreach($this->js as $key => $value)
{
$js[] = $this->js($key);
}
return implode("\n", $js);
}
if(!isset($this->js[$name]))
{
return null;
}
return HTML::tag('script', $this->js[$name], '');
}
Get all assets.
string
protected function all()
{
return trim(implode("\n\n", array($this->css(), $this->js())));
}
Performs calls on the chosen group instance.
| Type | Description |
|---|---|
| string | Method name |
| array | Method arguments |
mixed
public function __call($name, $arguments)
{
return call_user_func_array(array($this, $name), $arguments);
}
Performs calls on the default group instance.
| Type | Description |
|---|---|
| string | Method name |
| array | Method arguments |
mixed
public static function __callStatic($name, $arguments)
{
return call_user_func_array(array(static::group(), $name), $arguments);
}