/** * 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'); }
/** * Move a local content to the remote filesystem. * * @param array $content */ public function moveContentToRemote($content) { $this->manager->put('remote://' . $this->normalizeRemotePath($content['path']), $this->manager->read('local://' . $content['path'])); }
/** * 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'); }
/** * 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); } } } } }