Generates files and contents in the provided destination directory.

@param  $destination
@return array
762294
public function generateContent($destination)
    {
        $pathsWrittenTo = [];

        $packageStructure = $this->pathManager->emitStructure($destination);

        // At this point, since the file structure has been emitted we can add the
        // PathManager's file name collector to the template renderer so that the
        // 'path' (and other) functions work as expected.
        $this->getRenderer()->addCollector($this->getPathManager()->getCollector());
        $this->getRenderer()->addCollector(app(InputCollector::class));
        
        $this->pathManager->getRenderer()->setIgnoreUnloadedTemplateErrors(true);

        foreach ($packageStructure as $packageFile) {
            if ($this->fileSystem->exists($packageFile['full'])) {
                if (!$this->shouldCopyFileInstead($packageFile['original'])) {
                    $packageFileContents = $this->pathManager->getRenderer()->render($packageFile['original']);

                    if ($packageFileContents != null && strlen($packageFileContents) > 0) {
                        $this->fileSystem->put($packageFile['full'], $packageFileContents);
                        $pathsWrittenTo[] = $packageFile;
                    }
                } else {
                    // Copy the file instead.
                    $this->fileSystem->copy($packageFile['origin'], $packageFile['full']);
                }
            }
        }

        $this->pathManager->getRenderer()->setIgnoreUnloadedTemplateErrors(false);

        return $pathsWrittenTo;
    }
1226666
private function generateRoutes($directory)
    {
        $dirPath = $directory . 'app/routes/';

        if( ! file_exists($dirPath) )
            return;

        // get all files recursively

        /** @var \Iterator $iterator */
        $iterator = Finder::create()
            ->files()
            ->ignoreDotFiles(true)
            ->sortByName()
            ->in($dirPath);

        // iterate to array
        $files = iterator_to_array($iterator, true);

        $finalContent = '<?php' . "\r\n";

        foreach ( $files as $file ) {
            $finalContent .= "\r\n";
            $finalContent .= '//' . implode('/', array_slice(explode('/', $file), -6)) . "\r\n";
            $finalContent .= str_replace('<?php', '', file_get_contents((string)$file)) . "\r\n";
        }

        file_put_contents($directory . HCRoutes::ROUTES_PATH, $finalContent);

        $this->comment($directory . HCRoutes::ROUTES_PATH . ' file generated');
    }
1305834
static function contents($directory) {
        if (!self::exists($directory)) return null;

        $dircontents = [];

        $contents = scandir($directory);

        foreach ($contents as $content) {
            if ($content != '.' && $content != '..') {
                array_push($dircontents, $content);
            }
        }

        return $dircontents;
    }
45547
public function files($directory)
    {
        $directory = ltrim($directory, "/");
        $files = array();

        $dirIterator = new RecursiveDirectoryIterator($this->pathRoot.$directory);
        $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
        
        foreach ($iterator as $file) {
            if (filetype($file) == 'file') {
                $files[] = strval($file);
            }
        }
        
        return $files;
    }
678465
public function cast(string $destination)
    {
        if (!is_subclass_of($destination, get_class($this))) {
            throw new \InvalidArgumentException(sprintf(
                '%s is not a descendant of $object class: %s.',
                $destination,
                get_class($this)
            ));
        }

        $data = Serializer::serialize($this);
        $data['@type'] = $destination;

        $reflection = new \ReflectionClass($destination);
        $return = $reflection->newInstanceWithoutConstructor();
        Serializer::unserialize($return, $data);

        return $return;
    }
266056
private function getFileContents($file)
    {
        if (!isset($this->filesContent[$file])) {
            $this->filesContent[$file] = file_exists($file) ? file($file) : [];
        }

        return $this->filesContent[$file];
    }
110281
public function copy( $source, $destination ) {

		$source = $this->get_file( $source );

		if ( false === $source ) {
			return false;
		}

		$destination_parent = $this->get_file( dirname( $destination ) );
		$filename = basename( $destination );

		if ( false === $destination_parent ) {
			return false;
		}

		$destination_parent->contents->$filename = clone $source;

		return true;
	}
4702
public function extend($source, $destination)
    {
        foreach($source as $key => $value)
        {
            $destination->{$key} = $value;
        }

        return $destination;
    }
188242
protected function getMigrationFilesFromDirectory(String $directory) : Array
	{
		$files = [];
		$tableMigrationsClassFile = $directory . '/' . Migration::DEFAULT_MIGRATION_FILENAME . '.php';

		foreach(glob($directory . '/*' . '.php') as $file) {
			if ($file !== $tableMigrationsClassFile) {
				$files[] = $file;
			}
		}

		return $files;
	}
127602
public function content(): array
    {
        $dirs = collect($this->storage->allDirectories($this->root));
        $output = [];

        $dirs->filter(function ($dir) {
            $parts = $this->split($dir);
            return !in_array($parts[0], $this->exclude);
        })->each(function ($dir) use (&$output) {
            $curr = &$output;
            foreach ($this->split($dir) as $name) {
                if (!collect($curr)->contains('name', $name)) {
                    $curr[] = [
                        'path' => $this->dirToPath($dir),
                        'name' => $name,
                        'children' => []
                    ];
                } else {
                    foreach ($curr as $key => $item) {
                        if ($item['name'] === $name)
                            $curr = &$curr[$key]['children'];
                    }
                }
            }
        });

        return $output;
    }
143347
public function copyDirectory($directory, $destination)
    {
        $files = $this->fileSystem->allFiles($directory);
        $fileDeployed = false;
        $this->fileSystem->copyDirectory($directory, $destination);

        foreach ($files as $file) {
            $fileContents = $this->fileSystem->get($file);
            $fileDeployed = $this->fileSystem->put($destination.'/'.$file->getRelativePathname(), $fileContents);
        }

        return $fileDeployed;
    }
1088964
public function copy($destination) {
    
    if (!$this->exists()) {
      throw new Exception('Source from copy does not exist: '.$this);
    }
    
    if ($destination instanceof Dir) {
      $destination = $destination->getFile($this->getName());
    } elseif (!($destination instanceof File)) {
      throw new InvalidArgumentException('Invalid Argument. $destination must be file or dir');
    }

    if (!$destination->getDirectory()->exists()) {
      throw new Exception('The directory from the destination file does not exist: '.$destination);
    }

    $ret = @copy((string) $this, (string) $destination);

    if (!$ret) {
      throw new Exception('PHP Error while copying '.$this.' onto '.$destination);
    }
    
    return $this;
  }
488025
private function makeArrayFromOptionsWithVoidValues(array $source, array &$destination): array
    {
        $destination = [];

        foreach ($source as $option) {
            $destination[trim($option, "- ")] = "";
        }

        return $destination;
    }
1324642
protected function getFreshMigrations($source, $destination)
	{
		$me = $this;

		return array_filter($this->getPackageMigrations($source), function($file) use ($me, $destination)
		{
			return ! $me->migrationExists($file, $destination);
		});
	}
404825
public static function copyRecursive($source, $destination)
    {
        if (!is_dir($destination)) {
            mkdir($destination);
        }

        $dir = opendir($source);

        if (!$dir) {
            throw new RuntimeException("Cannot copy '$source' to '$destination'");
        }

        while (false !== ($file = readdir($dir))) {
            if ($file != '.' && $file != '..') {
                if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
                    static::copyRecursive(
                        $source . DIRECTORY_SEPARATOR . $file,
                        $destination . DIRECTORY_SEPARATOR . $file
                    );
                } else {
                    copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
                }
            }
        }
        closedir($dir);
    }
503402
public function listContents($directory = '', $recursive = false)
    {
        $files = [];
        foreach($this->listDirContents($directory) as $k => $file) {
            $pathInfo = pathinfo($file['key']);
            $files[] = array_merge($pathInfo, $this->normalizeData($file), [
                'type' => isset($pathInfo['extension']) ? 'file' : 'dir',
            ]);
        }
        return $files;
    }
247965
public function exportFiles($content)
    {
        $content = $this->_defaultData($content);
        if ($content->file && (strpos($content->file, '/') === 0 || strpos($content->file, URL::to('/')) === 0)) {
            return [str_replace(URL::to('/'), '', $content->file)];
        } else {
            return [];
        }
    }