Skip to content

Commit

Permalink
update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
oohnoitz committed Jan 22, 2015
1 parent a949f90 commit 20453e1
Show file tree
Hide file tree
Showing 13 changed files with 816 additions and 891 deletions.
16 changes: 1 addition & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
.*
._*
.DS_Store
.svn
!.gitignore
Desktop.ini
Thumbs.db

.fuelphp-phpstorm
.idea
nbproject

fuel/app/logs/*/*/*
fuel/app/cache/*/*
/vendor/
vendor/
15 changes: 0 additions & 15 deletions bootstrap.php

This file was deleted.

249 changes: 120 additions & 129 deletions classes/Foolz/Package/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,133 +4,124 @@

class AssetManager
{
/**
* The package creating this object
*
* @var \Foolz\Package\Package|null
*/
protected $package = null;

/**
* The directory where the files should be put so they are reachable via an URL
*
* @var string
*/
protected $public_dir = "";

/**
* The base URL where the package files can be found at
*
* @var string
*/
protected $base_url = "";

/**
* Check if the package extends another, avoids some file checks
*
* @var bool
*/
protected $does_extend = true;

/**
* Create a new instance of the asset manager
*
* @param \Foolz\Package\Package $package The reference to the package creating this asset manager
*
* @return \Foolz\Package\AssetManager
*/
public function __construct(\Foolz\Package\Package $package)
{
$this->package = $package;
$this->public_dir = $this->getPackage()->getLoader()->getPublicDir();
$this->base_url = $this->getPackage()->getLoader()->getBaseUrl();

// load the assets
if ( ! file_exists($this->getPublicDir()))
{
$this->clearAssets();
$this->loadAssets();
}

try
{
$this->getPackage()->getExtended();
$this->does_extend = true;
}
catch (\OutOfBoundsException $e)
{
$this->does_extend = false;
}

}

/**
* Returns the Package object that created this instance of AssetManager
*
* @return \Foolz\Package\Package|null The Package object that created this instance of AssetManager
*/
public function getPackage()
{
return $this->package;
}

/**
* Returns the path to the directory where the public files get loaded
*
* @return string The path
*/
protected function getPublicDir()
{
return $this->public_dir.$this->getPackage()->getConfig('name')
.'/assets-'.$this->getPackage()->getConfig('version').'/';
}

/**
* Returns an URL to the asset being requested
*
* @param $path $path The relative path to the asset to link to
*
* @return string The full URL to the asset
*/
public function getAssetLink($path)
{
$candidate = $this->base_url.$this->getPackage()->getConfig('name')
.'/assets-'.$this->getPackage()->getConfig('version').'/'.$path;

if ( ! $this->does_extend || file_exists($this->getPublicDir().$path))
{
return $candidate;
}

return $this->getPackage()->getExtended()->getAssetManager()->getAssetLink($path);
}

/**
* Loads all the asset files from the package folder
*/
protected function loadAssets()
{
if ( ! file_exists($this->getPublicDir()))
{
mkdir($this->getPublicDir(), 0777, true);
}

Util::copy($this->getPackage()->getDir().'assets', rtrim($this->getPublicDir(), '/'));
}

/**
* Clears all the files in the public package directory
*
* @return \Foolz\Package\AssetManager The current object
*/
public function clearAssets()
{
// get it just right out of the assets folder
if (file_exists($this->public_dir.$this->getPackage()->getConfig('name')))
{
Util::delete($this->public_dir.$this->getPackage()->getConfig('name'));
}

return $this;
}
/**
* The package creating this object
*
* @var \Foolz\Package\Package|null
*/
protected $package = null;

/**
* The directory where the files should be put so they are reachable via an URL
*
* @var string
*/
protected $public_dir = '';

/**
* The base URL where the package files can be found at
*
* @var string
*/
protected $base_url = '';

/**
* Check if the package extends another, avoids some file checks
*
* @var bool
*/
protected $does_extend = true;

/**
* Create a new instance of the asset manager
*
* @param \Foolz\Package\Package $package The reference to the package creating this asset manager
*
* @return \Foolz\Package\AssetManager
*/
public function __construct(\Foolz\Package\Package $package)
{
$this->package = $package;
$this->public_dir = $this->getPackage()->getLoader()->getPublicDir();
$this->base_url = $this->getPackage()->getLoader()->getBaseUrl();

// load the assets
if (!file_exists($this->getPublicDir())) {
$this->clearAssets();
$this->loadAssets();
}

try {
$this->getPackage()->getExtended();
$this->does_extend = true;
} catch (\OutOfBoundsException $e) {
$this->does_extend = false;
}

}

/**
* Returns the Package object that created this instance of AssetManager
*
* @return \Foolz\Package\Package|null The Package object that created this instance of AssetManager
*/
public function getPackage()
{
return $this->package;
}

/**
* Returns the path to the directory where the public files get loaded
*
* @return string The path
*/
protected function getPublicDir()
{
return $this->public_dir.$this->getPackage()->getConfig('name')
.'/assets-'.$this->getPackage()->getConfig('version').'/';
}

/**
* Returns an URL to the asset being requested
*
* @param $path $path The relative path to the asset to link to
*
* @return string The full URL to the asset
*/
public function getAssetLink($path)
{
if (!$this->does_extend || file_exists($this->getPublicDir().$path)) {
return $this->base_url.$this->getPackage()->getConfig('name')
.'/assets-'.$this->getPackage()->getConfig('version').'/'.$path;
}

return $this->getPackage()->getExtended()->getAssetManager()->getAssetLink($path);
}

/**
* Loads all the asset files from the package folder
*/
protected function loadAssets()
{
if (!file_exists($this->getPublicDir())) {
mkdir($this->getPublicDir(), 0777, true);
}

Util::copy($this->getPackage()->getDir().'assets', rtrim($this->getPublicDir(), '/'));
}

/**
* Clears all the files in the public package directory
*
* @return \Foolz\Package\AssetManager The current object
*/
public function clearAssets()
{
// get it just right out of the assets folder
if (file_exists($this->public_dir.$this->getPackage()->getConfig('name'))) {
Util::delete($this->public_dir.$this->getPackage()->getConfig('name'));
}

return $this;
}
}
Loading

0 comments on commit 20453e1

Please sign in to comment.