Skip to content

Commit

Permalink
Add function_exists checks to helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed May 11, 2016
1 parent f39242f commit 493385b
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions includes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
* @param string $output
* @return void
*/
function info($output)
{
output('<info>' . $output . '</info>');
if (!function_exists('info')) {
function info($output)
{
output('<info>' . $output . '</info>');
}
}

/**
Expand All @@ -17,12 +19,14 @@ function info($output)
* @param string $output
* @return void
*/
function output($output)
{
if (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] == 'testing') {
return;
if (!function_exists('output')) {
function output($output)
{
if (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] == 'testing') {
return;
}
(new Symfony\Component\Console\Output\ConsoleOutput)->writeln($output);
}
(new Symfony\Component\Console\Output\ConsoleOutput)->writeln($output);
}

/**
Expand All @@ -32,27 +36,30 @@ function output($output)
* @param String $dest - Destination of files being moved
* @return bool
*/
function rcopy($src, $dest)
{

// If source is not a directory stop processing
if (!is_dir($src)) return false;
if (!function_exists('rcopy')) {
function rcopy($src, $dest)
{

// If the destination directory does not exist create it
if (!is_dir($dest)) {
if (!mkdir($dest)) {
// If the destination directory could not be created stop processing
return false;
// If source is not a directory stop processing
if (!is_dir($src)) return false;

// If the destination directory does not exist create it
if (!is_dir($dest)) {
if (!mkdir($dest)) {
// If the destination directory could not be created stop processing
return false;
}
}
}

// Open the source directory to read in files
$i = new DirectoryIterator($src);
foreach ($i as $f) {
if ($f->isFile()) {
copy($f->getRealPath(), "$dest/" . $f->getFilename());
} else if (!$f->isDot() && $f->isDir()) {
rcopy($f->getRealPath(), "$dest/$f");
// Open the source directory to read in files
$i = new DirectoryIterator($src);
foreach ($i as $f) {
if ($f->isFile()) {
copy($f->getRealPath(), "$dest/" . $f->getFilename());
} else if (!$f->isDot() && $f->isDir()) {
rcopy($f->getRealPath(), "$dest/$f");
}
}
}
}

0 comments on commit 493385b

Please sign in to comment.