Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
oohnoitz committed Jan 19, 2015
1 parent 276c2f1 commit a949f90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
6 changes: 3 additions & 3 deletions classes/Foolz/Package/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function loadAssets()
mkdir($this->getPublicDir(), 0777, true);
}

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

/**
Expand All @@ -128,9 +128,9 @@ public function clearAssets()
// get it just right out of the assets folder
if (file_exists($this->public_dir.$this->getPackage()->getConfig('name')))
{
Util::delete_recursive($this->public_dir.$this->getPackage()->getConfig('name'));
Util::delete($this->public_dir.$this->getPackage()->getConfig('name'));
}

return $this;
}
}
}
2 changes: 1 addition & 1 deletion classes/Foolz/Package/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,4 @@ public function getExtended()
throw new \OutOfBoundsException('No such package available for extension.');
}
}
}
}
37 changes: 15 additions & 22 deletions classes/Foolz/Package/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class Util
{

/**
* Returns the value of a deep associative array by using a dotted notation for the keys
*
Expand Down Expand Up @@ -56,8 +55,7 @@ public static function dottedConfig($config, $section, $fallback)
*/
public static function saveArrayToFile($path, $array)
{
$content = "<?php \n".
"return ".var_export($array, true).';';
$content = "<?php \n"."return ".var_export($array, true).';';

file_put_contents($path, $content);
}
Expand All @@ -72,7 +70,7 @@ public static function saveArrayToFile($path, $array)
* @param string $path The path to the file/directory to delete
* @return void
*/
public static function delete_recursive($path)
public static function delete($path)
{
if (is_dir($path)) {
$iterator = new RecursiveIteratorIterator(
Expand All @@ -83,15 +81,13 @@ public static function delete_recursive($path)
foreach ($iterator as $file) {
if ($file->isDir()) {
rmdir($file->getPathname());
}
else {
} else {
unlink($file->getPathname());
}
}

rmdir($path);
}
else {
} else {
unlink($path);
}
}
Expand All @@ -101,30 +97,27 @@ public static function delete_recursive($path)
*
* From: http://davidhancock.co/2012/11/useful-php-functions-for-dealing-with-the-file-system/
*
* @param string $source The path to the source file/directory
* @param string $dest The path to the destination directory
* @param string $src The path to the source file/directory
* @param string $dst The path to the destination directory
* @return void
*/
public static function copy_recursive($source, $dest)
public static function copy($src, $dst)
{
if (is_dir($source)) {
if (is_dir($src)) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
new RecursiveDirectoryIterator($src, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);

foreach ($iterator as $file) {
if ($file->isDir()) {
mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName());
}
else {
copy($file, $dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName());
mkdir($dst.DIRECTORY_SEPARATOR.$iterator->getSubPathName());
} else {
copy($file, $dst.DIRECTORY_SEPARATOR.$iterator->getSubPathName());
}
}
}
else {
copy($source, $dest);
} else {
copy($src, $dst);
}
}

}
}

0 comments on commit a949f90

Please sign in to comment.