예제 #1
0
 /**
  * Upload a file.
  *
  * @param UploadedFile    $file
  * @param FolderInterface $folder
  * @return bool|FileInterface
  */
 public function upload(UploadedFile $file, FolderInterface $folder)
 {
     $rules = 'required';
     if ($allowed = $folder->getAllowedTypes()) {
         $rules .= '|mimes:' . implode(',', $allowed);
     }
     $validation = $this->validator->make(['file' => $file], ['file' => $rules]);
     if (!$validation->passes()) {
         return false;
     }
     $disk = $folder->getDisk();
     /* @var FileInterface $entry */
     $entry = $this->manager->put($disk->getSlug() . '://' . $folder->getSlug() . '/' . $file->getClientOriginalName(), file_get_contents($file->getRealPath()));
     if (in_array($entry->getExtension(), $this->config->get('anomaly.module.files::mimes.types.image'))) {
         $size = getimagesize($file->getRealPath());
         $this->files->save($entry->setAttribute('width', $size[0])->setAttribute('height', $size[1]));
     }
     return $entry;
 }
 /**
  * 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');
 }
예제 #3
0
 /**
  * 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']));
 }
예제 #4
0
 /**
  * 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))));
 }
예제 #5
0
 /**
  * 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');
 }
예제 #6
0
    /**
     * 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);
                    }
                }
            }
        }
    }