/** * Publish the directory to the given directory. * * @param string $from * @param string $to * * @return void */ protected function publishDirectory($from, $to) { $manager = new MountManager(['from' => new Flysystem(new LocalAdapter($from)), 'to' => new Flysystem(new LocalAdapter($to))]); foreach ($manager->listContents('from://', true) as $file) { if ($file['type'] === 'file') { $manager->put('to://' . $file['path'], $manager->read('from://' . $file['path'])); } } $this->status($from, $to, 'Directory'); }
/** * Moves the contents of an Atuin App into the server's Atuin Filesystem * * @param \League\Flysystem\MountManager $manager */ protected function moveAppContents($directory, $manager) { $contents = $manager->listContents('source://' . $directory); foreach ($contents as $entry) { if ($entry['type'] == 'dir') { $this->moveAppContents($entry['path'], $manager); } else { $manager->put('local://' . $entry['path'], $manager->read('source://' . $entry['path']), ['visibility' => AdapterInterface::VISIBILITY_PUBLIC]); } } }
/** * Get directories in the local filesystem from a path. * * @param string $path * * @return array An array of paths. Paths are relative. */ public function getDirectories($path) { if ($path == '.') { $path = ''; } $directories = []; $contents = $this->manager->listContents('local://' . $path); foreach ($contents as $content) { // Remember the path if we've found a directory if ($content['type'] == 'dir') { $directories[] = $content['path']; } } return $directories; }
/** * Publish directory to application. * * @author Morten Rugaard <*****@*****.**> * * @param string $from * @param string $to * * @return void */ protected final function publishDirectory($from, $to) { // Load mount manager $manager = new MountManager(['from' => new Flysystem(new LocalAdapter($from)), 'to' => new Flysystem(new LocalAdapter($to))]); // Copy directory to application foreach ($manager->listContents('from://', true) as $file) { if ($file['type'] !== 'file') { continue; } $manager->put(sprintf('to://%s', $file['path']), $manager->read(sprintf('from://%s', $file['path']))); } // Output status message $this->getCommand()->line(sprintf('<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>', 'Directory', str_replace(base_path(), '', realpath($from)), str_replace(base_path(), '', realpath($to)))); }
/** * Publish the directory to the given directory. * * @param string $from * @param string $to * * @return void */ protected function publishDirectory($from, $to) { $manager = new MountManager(['from' => new Flysystem(new LocalAdapter($from)), 'to' => new Flysystem(new LocalAdapter($to))]); foreach ($manager->listContents('from://', true) as $file) { $path = $file['path']; if (substr($path, 0, 8) === 'database' || substr($path, 0, 15) === 'resources/views') { continue; } if ($file['type'] === 'file' && (!$manager->has('to://' . $file['path']) || $this->option('force'))) { $manager->put('to://' . $file['path'], $manager->read('from://' . $file['path'])); } } $this->status($from, $to, 'Directory'); }
public function testFileWithAliasWithMountManager() { $fs = $this->mockFilesystem(); $fs2 = $this->mockFilesystem(); $mountManager = new MountManager(); $mountManager->mountFilesystem('local', $fs); $mountManager->mountFilesystem('huge', $fs2); $results = $mountManager->listContents("local://tests/files"); foreach ($results as $result) { $this->assertArrayHasKey('filesystem', $result); $this->assertEquals($result['filesystem'], 'local'); } $results = $mountManager->listContents("huge://tests/files"); foreach ($results as $result) { $this->assertArrayHasKey('filesystem', $result); $this->assertEquals($result['filesystem'], 'huge'); } }
/** * Search and remplace all occurences of * TypiCMS\Modules\<Module> to TypiCMS\Modules\<Module>\Shells */ public function buildShellClasses() { $directory = base_path('Modules/' . $this->module . '/Shells'); $manager = new MountManager(['directory' => new Flysystem(new LocalAdapter($directory))]); foreach ($manager->listContents('directory://', true) as $file) { if ($file['type'] === 'file') { $source = $manager->read('directory://' . $file['path']); $matches = []; if (preg_match('|namespace[ ]+(.*);|', $source, $matches)) { $namespace = preg_replace('|TypiCMS\\\\Modules\\\\([\\w]+)|', "TypiCMS\\\\Modules\\\\\$1\\\\Shells", $matches[1]); $baseNamespace = str_replace('\\Shells', '', $namespace); if (preg_match('/(class|interface|trait) +(\\w+)(.*)?/', $source, $matches)) { $structureType = $matches[1]; $classname = $matches[2]; $implementsUseLine = ''; $implements = ''; if ($additional = $matches[3]) { if (preg_match('|implements +(\\w+)|', $additional, $matches)) { //dd($matches); $implements = $matches[1]; if ($implements) { if (preg_match('|use[ ]+(.*)' . preg_quote($implements) . ';|', $source, $matches)) { // there is use clause for the implemented interface if (preg_match('|TypiCMS|', $matches[1])) { $implementsUseLine = preg_replace('|TypiCMS\\\\Modules\\\\([\\w]+)|', "TypiCMS\\\\Modules\\\\\$1\\\\Shells", $matches[0]); } else { $implementsUseLine = $matches[0]; } } } } } if ($structureType == 'trait') { $content = '<?php namespace ' . $namespace . '; use ' . $baseNamespace . '\\' . $classname . ' as BaseTrait; ' . $structureType . ' ' . $classname . ' { use BaseTrait; } '; } else { $content = '<?php namespace ' . $namespace . '; use ' . $baseNamespace . '\\' . $classname . ' as Base' . ucfirst($structureType) . '; ' . ($implementsUseLine ? $implementsUseLine . "\n" : '') . ' ' . $structureType . ' ' . $classname . ' extends Base' . ucfirst($structureType) . '' . ($implements ? ' implements ' . $implements : '') . ' { } '; } $manager->put('directory://' . $file['path'], $content); } } } } }