コード例 #1
1
ファイル: FileEntity.php プロジェクト: svobodni/web
 /**
  * @ORM\PreFlush()
  */
 public function preUpload()
 {
     if ($this->file) {
         if ($this->file instanceof FileUpload) {
             $basename = $this->file->getSanitizedName();
             $basename = $this->suggestName($this->getFilePath(), $basename);
             $this->setName($basename);
         } else {
             $basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-');
             $basename = $this->suggestName(dirname($this->file->getPathname()), $basename);
             $this->setName($basename);
         }
         if ($this->_oldPath && $this->_oldPath !== $this->path) {
             @unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath));
         }
         if ($this->file instanceof FileUpload) {
             $this->file->move($this->getFilePath());
         } else {
             copy($this->file->getPathname(), $this->getFilePath());
         }
         return $this->file = NULL;
     }
     if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) {
         $oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path);
         if (file_exists($oldFilePath)) {
             rename($oldFilePath, $this->getFilePath());
         }
     }
 }
コード例 #2
0
 /**
  * Test is files or directories passed as arguments are empty.
  * Only valid for regular files and directories.
  *
  * @param mixed $files String or array of strings of path to files and directories.
  *
  * @return boolean True if all arguments are empty. (Size 0 for files and no children for directories).
  */
 public function isEmpty($files)
 {
     if (!$files instanceof \Traversable) {
         $files = new \ArrayObject(is_array($files) ? $files : array($files));
     }
     foreach ($files as $file) {
         if (!$this->exists($file)) {
             throw new FileNotFoundException(null, 0, null, $file);
         }
         if (is_file($file)) {
             $file_info = new \SplFileInfo($file);
             if ($file_info->getSize() !== 0) {
                 return false;
             }
         } elseif (is_dir($file)) {
             $finder = new Finder();
             $finder->in($file);
             $it = $finder->getIterator();
             $it->rewind();
             if ($it->valid()) {
                 return false;
             }
         } else {
             throw new IOException(sprintf('File "%s" is not a directory or a regular file.', $file), 0, null, $file);
         }
     }
     return true;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->factory = new ProcessFactory('pwd');
     $this->directory = \Mockery::mock(\SplFileInfo::class);
     $this->directory->shouldReceive('__toString')->andReturn('/tmp');
 }
コード例 #4
0
 /**
  * @param \SplFileInfo $basePath
  * @param Property $property
  * @return self
  */
 public static function fromProperty(\SplFileInfo $basePath, Property $property)
 {
     $filePath = sprintf(self::FILE_PATH_FORMAT, $basePath->getPathname(), $property);
     $fileInfo = new \SplFileInfo($filePath);
     $file = new PHPFile($fileInfo);
     return new self($file, $property);
 }
コード例 #5
0
ファイル: IncludeCompiler.php プロジェクト: koolkode/k2
 protected function generateSourceCode(ParsedType $type, SourceBuffer $buffer, \SplFileInfo $file)
 {
     $extends = array_map(function ($t) {
         return '\\' . ltrim($t, '\\');
     }, $type->getExtends());
     $extends = empty($extends) ? '' : implode(', ', $extends);
     $implements = ['\\' . MergedSourceInterface::class];
     // Double inclusion safeguard:
     if ($type->isClass()) {
         $safe1 = sprintf(' if(!class_exists(%s, false)) { ', var_export($type->getName(), true));
         $safe2 = ' } ';
     } elseif ($type->isInterface()) {
         $safe1 = sprintf(' if(!interface_exists(%s, false)) { ', var_export($type->getName(), true));
         $safe2 = ' } ';
     } else {
         $safe1 = sprintf(' if(!trait_exists(%s, false)) { ', var_export($type->getName(), true));
         $safe2 = ' } ';
     }
     $generator = new SourceGenerator($buffer);
     $generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_INTERFACES, implode(', ', $implements));
     $generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_NAME, $type->getLocalName());
     $generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_SUPERCLASS, $extends);
     $generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_PREPENDED_CODE, $safe1);
     $generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_EXTERNAL_CODE, $safe2);
     $code = trim($generator->generateCode($file->getPathname(), dirname($file->getPathname())));
     $code = preg_replace("'^<\\?(?:php)?'i", '', $code) . "\n";
     return $code;
 }
コード例 #6
0
 /**
  * @param \SplFileInfo $file
  *
  * @return string
  */
 public function name(\SplFileInfo $file)
 {
     if ($file instanceof UploadedFile) {
         return $this->escape($file->getClientOriginalName());
     }
     return parent::name($file);
 }
コード例 #7
0
 /**
  * Stores the file object.
  *
  * @param \SplFileInfo $file The file object
  *
  * @throws \InvalidArgumentException If $file is not a file
  */
 public function __construct(\SplFileInfo $file)
 {
     if (!$file->isFile()) {
         throw new \InvalidArgumentException(sprintf('%s is not a file.', $file));
     }
     $this->file = $file;
 }
コード例 #8
0
/**
 * Recursively create a directory if allowed.
 *
 * @param string $path     The path to the directory which will be created.
 * @param int $permissions The Unix permissions to set on the directory. Ignored
 *                         on Windows machines.
 *
 * @return void
 *
 * @throws \LogicException           if the directory already exists.
 * @throws \UnexpectedValueException if the first existing parent directory in
 *                                   the $path argument is not readable or
 *                                   writable by the user running PHP.
 * @throws \UnexpectedValueException when a recursive call to mkdir() with the
 *                                   given $path and $permissions arguments
 *                                   fails.
 */
function createDirectory($path, $permissions = 0755)
{
    if (is_dir($path)) {
        throw new \LogicException('De map "' . $path . '" bestaat al.', 2);
    }
    // Find the first parent directory and check its permissions.
    $permission = false;
    $parentPath = $path;
    do {
        $parentPath = explode(DIRECTORY_SEPARATOR, trim($parentPath, DIRECTORY_SEPARATOR));
        $parentPathCount = count($parentPath);
        unset($parentPath[--$parentPathCount]);
        $parentPath = implode(DIRECTORY_SEPARATOR, $parentPath);
        // Don't prepend the path with a directory separator on Windows.
        // The drive letter, for example: "C:\", is enough.
        if (PHP_OS !== 'Windows') {
            $parentPath = DIRECTORY_SEPARATOR . $parentPath;
        }
        if (file_exists($parentPath)) {
            $fileInfo = new \SplFileInfo($parentPath);
            if ($fileInfo->isReadable() && $fileInfo->isWritable()) {
                $permission = true;
                break;
            }
        }
    } while ($parentPathCount > 1);
    if ($permission) {
        if (!mkdir($path, $permissions, true)) {
            throw new \UnexpectedValueException('De map "' . $path . '" kon niet aangemaakt worden.', 8);
        }
    } else {
        throw new \UnexpectedValueException('De eerstvolgende bestaande map die boven "' . $path . '" ligt ' . 'is niet lees- of schrijfbaar.', 4);
    }
}
コード例 #9
0
 /**
  * @param \SplFileInfo $data
  * @return bool
  */
 public function supports($data)
 {
     if (!$data instanceof \SplFileInfo) {
         return false;
     }
     return strtolower($data->getExtension()) == "php";
 }
コード例 #10
0
ファイル: ExtensionManager.php プロジェクト: g4z/poop
 /**
  * Load all extension classes
  */
 public function load()
 {
     $counter = 0;
     foreach (glob(__DIR__ . '/Extension/*.php') as $filename) {
         $file = new \SplFileInfo($filename);
         $classname = $file->getBasename('.php');
         $classpath = sprintf('%s\\Extension\\%s', __NAMESPACE__, $classname);
         require_once $filename;
         $extension = new \ReflectionClass($classpath);
         $instance = $extension->newInstance($this->getParent());
         foreach ($extension->getMethods() as $method) {
             if (mb_substr($method->name, 0, 3) == 'FN_') {
                 $map = new \StdClass();
                 $map->class = $extension->getShortName();
                 $map->method = $method->name;
                 $map->instance = $instance;
                 $tag = sprintf('%s.%s', mb_strtolower($classname), mb_substr($method->name, 3));
                 $this->mapping[$tag] = $map;
             }
         }
         $this->debug(__METHOD__, __LINE__, sprintf('Loaded extension: %s', $extension->getShortName()));
         // save the instance
         $this->instances[] = $instance;
         $counter++;
     }
     return $counter;
 }
コード例 #11
0
ファイル: Export.php プロジェクト: cwd/TableBundle
 function __construct(\SplFileInfo $file, $contentType, $filename = null, $fileExtension = null)
 {
     $this->file = $file;
     $this->filename = $filename ?: $file->getBasename();
     $this->contentType = $contentType;
     $this->fileExtension = $fileExtension ?: $file->getExtension();
 }
コード例 #12
0
ファイル: Download.php プロジェクト: fbf/laravel-downloads
 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function (\Eloquent $model) {
         // If a new download file is uploaded, could be create or edit...
         $dirty = $model->getDirty();
         if (array_key_exists('filename', $dirty)) {
             $file = new \SplFileInfo($model->getAbsolutePath());
             $model->filesize = $file->getSize();
             $model->extension = strtoupper($file->getExtension());
             // Now if editing only...
             if ($model->exists) {
                 $oldFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('filename');
                 $newFilename = $dirty['filename'];
                 // Delete the old file if the filename is different to the new one, and it therefore hasn't been replaced
                 if ($oldFilename != $newFilename) {
                     $model->deleteFile($oldFilename);
                 }
             }
         }
         // If a download is edited and the image is changed...
         if (array_key_exists('image', $dirty) && $model->exists) {
             $oldImageFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('image');
             $model->deleteImageFiles($oldImageFilename);
         }
     });
     static::deleted(function ($model) {
         $model->deleteFile();
         $model->deleteImageFiles();
     });
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filename = $input->getOption('filename');
     if (!$filename) {
         $resource = STDIN;
     } else {
         try {
             $file = new \SplFileInfo($filename);
         } catch (\Exception $e) {
             throw new \InvalidArgumentException('Bad filename');
         }
         $resource = fopen($file->getRealPath(), 'rb');
     }
     $width = $input->getArgument('width');
     $height = $input->getArgument('height');
     $dim = $input->getArgument('dim');
     if (!$width) {
         $width = VisualizationEqualizer::WIDTH_DEFAULT;
     }
     if (!$height) {
         $height = VisualizationEqualizer::HEIGHT_DEFAULT;
     }
     if (!$dim) {
         $dim = VisualizationEqualizer::DIM_DEFAULT;
     }
     $render = new ConsoleRender($output);
     $render->setDisplayColor(true);
     $wavReader = new WavReader($resource, new Riff(), new Fmt(), new Data());
     $visualizationEqualizer = new VisualizationEqualizer($resource, $dim, $wavReader, $render);
     $visualizationEqualizer->run((int) $width, (int) $height);
 }
コード例 #14
0
 public function src($src, $ext = null)
 {
     if (!is_file($src)) {
         throw new FileNotFoundException($src);
     }
     $this->src = $src;
     if (!$ext) {
         $info = new \SplFileInfo($src);
         $this->ext = strtoupper($info->getExtension());
     } else {
         $this->ext = strtoupper($ext);
     }
     if (is_file($src) && ($this->ext == "JPG" or $this->ext == "JPEG")) {
         $this->image = ImageCreateFromJPEG($src);
     } else {
         if (is_file($src) && $this->ext == "PNG") {
             $this->image = ImageCreateFromPNG($src);
         } else {
             throw new FileNotFoundException($src);
         }
     }
     $this->input_width = imagesx($this->image);
     $this->input_height = imagesy($this->image);
     return $this;
 }
コード例 #15
0
ファイル: Compiler.php プロジェクト: bcncommerce/magebuild
 private function addFile(\Phar $phar, \SplFileInfo $file)
 {
     $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
     $content = file_get_contents($file);
     $content = $this->stripWhitespace($content);
     $phar->addFromString($path, $content);
 }
コード例 #16
0
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $namespace = false;
     $classyName = null;
     $classyIndex = 0;
     foreach ($tokens as $index => $token) {
         if ($token->isGivenKind(T_NAMESPACE)) {
             if (false !== $namespace) {
                 return;
             }
             $namespace = true;
         } elseif ($token->isClassy()) {
             if (null !== $classyName) {
                 return;
             }
             $classyIndex = $tokens->getNextMeaningfulToken($index);
             $classyName = $tokens[$classyIndex]->getContent();
         }
     }
     if (null === $classyName) {
         return;
     }
     if (false !== $namespace) {
         $filename = basename(str_replace('\\', '/', $file->getRealPath()), '.php');
         if ($classyName !== $filename) {
             $tokens[$classyIndex]->setContent($filename);
         }
     } else {
         $normClass = str_replace('_', '/', $classyName);
         $filename = substr(str_replace('\\', '/', $file->getRealPath()), -strlen($normClass) - 4, -4);
         if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
             $tokens[$classyIndex]->setContent(str_replace('/', '_', $filename));
         }
     }
 }
コード例 #17
0
ファイル: dir.php プロジェクト: greor/satin-spb
 /**
  * This function will make directory writable.
  *
  * @param   string  path
  * @return  void
  * @throw   Kohana_Exception
  */
 public static function make_writable($path, $chmod = NULL)
 {
     try {
         $dir = new SplFileInfo($path);
         if ($dir->isFile()) {
             throw new Kohana_Exception('Could not make :path writable directory because it is regular file', array(':path' => Debug::path($path)));
         } elseif ($dir->isLink()) {
             throw new Kohana_Exception('Could not make :path writable directory because it is link', array(':path' => Debug::path($path)));
         } elseif (!$dir->isDir()) {
             // Try create directory
             Ku_Dir::make($path, $chmod);
             clearstatcache(TRUE, $path);
         }
         if (!$dir->isWritable()) {
             // Try make directory writable
             chmod($dir->getRealPath(), $chmod === NULL ? Ku_Dir::$default_dir_chmod : $chmod);
             clearstatcache(TRUE, $path);
             // Check result
             if (!$dir->isWritable()) {
                 throw new Exception('Make dir writable failed', 0);
             }
         }
     } catch (Kohana_Exception $e) {
         // Rethrow exception
         throw $e;
     } catch (Exception $e) {
         throw new Kohana_Exception('Could not make :path directory writable', array(':path' => Debug::path($path)));
     }
 }
コード例 #18
0
 function it_does_not_change_not_updated_file()
 {
     $file = new \SplFileInfo(__FILE__);
     $changes = ['data' => ['filePath' => $file->getPath()]];
     $originals = ['data' => ['filePath' => $file->getPath()]];
     $this->compare($changes, $originals)->shouldReturn(null);
 }
コード例 #19
0
ファイル: FileFilterIterator.php プロジェクト: thekabal/tki
 private function getFileRelativePathname(\SplFileInfo $file)
 {
     if ($file instanceof SymfonySplFileInfo) {
         return $file->getRelativePathname();
     }
     return $file->getPathname();
 }
コード例 #20
0
 function it_cuts_the_filename_if_it_is_too_long(\SplFileInfo $file)
 {
     $file->getFilename()->willReturn('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.pdf');
     $file->getExtension()->willReturn('pdf');
     $pathInfo = $this->generate($file);
     $pathInfo->shouldBeValidPathInfo('Lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit__sed_do_eiusmod_tempor_incididunt_ut_la.pdf');
 }
コード例 #21
0
ファイル: class.file.php プロジェクト: brendo/bulkimporter
 public function __construct(SplFileInfo $file)
 {
     $this->file = $file;
     $this->location = $file->getRealPath();
     $this->name = preg_replace('/\\.' . preg_quote(General::getExtension($file)) . '$/', null, $file->getFilename());
     $this->errors = array();
 }
コード例 #22
0
ファイル: ExtractedFile.php プロジェクト: brodaproject/broda
 public function __destruct()
 {
     if ($this->unlinkOnDestroy) {
         @unlink($this->file->getPathname());
         @rmdir(dirname($this->file->getPathname()));
     }
 }
コード例 #23
0
ファイル: PhybridPage.php プロジェクト: centorino/phybrid
 public function __construct($file, $app = null)
 {
     $env = $app->environment;
     $info = new \SplFileInfo($file);
     $this->type = $info->getExtension();
     $file_text = file_get_contents($file);
     $file_header = substr($file_text, 0, strpos($file_text, '}') + 1);
     $file_header = json_decode($file_header, true);
     $page_path = ltrim(str_replace($env['PAGES_ROOT_PATH'], '', $file), '/');
     $this->id = str_replace('.' . $this->type, '', $page_path);
     $this->header = $file_header;
     if (!isset($this->header['order'])) {
         $this->header['order'] = '';
     }
     $file_body = substr_replace($file_text, '', 0, strpos($file_text, '}') + 2);
     $this->contents = $file_body;
     if ($this->type == 'md') {
         $this->contents = str_replace('@@siteurl@@', $env['ROOT_PATH'], $this->contents);
         $this->contents = Markdown::defaultTransform($this->contents);
     } else {
         if ($this->type == 'html') {
             $this->contents = str_replace('@@siteurl@@', $env['ROOT_PATH'], $this->contents);
         } else {
             if ($this->type == 'txt') {
                 $this->contents = '<p>' . str_replace("\n", '</p><p>', $this->contents) . '</p>';
             }
         }
     }
 }
コード例 #24
0
ファイル: UpdateSitemapCommand.php プロジェクト: Quiss/Evrika
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fileInfo = new \SplFileInfo($this->getContainer()->getParameter('kernel.root_dir') . '/../web/sitemap.xml');
     if ($fileInfo->isFile() && $fileInfo->isReadable()) {
         $output->write('Reading sitemap.xml...');
         $file = $fileInfo->openFile();
         $xml = '';
         while (!$file->eof()) {
             $xml .= $file->fgets();
         }
         $output->writeln(' done.');
         $output->write('Updating sitemap.xml...');
         $sitemap = new \SimpleXMLIterator($xml);
         $sitemap->rewind();
         $lastmodDate = new \DateTime();
         $lastmodDate->sub(new \DateInterval('P1D'));
         $lastmodDateFormatted = $lastmodDate->format('Y-m-d');
         while ($sitemap->valid()) {
             $sitemap->current()->lastmod = $lastmodDateFormatted;
             $sitemap->next();
         }
         $file = $file->openFile('w');
         $file->fwrite($sitemap->asXML());
         $output->writeln(' done.');
     } else {
         $output->writeln('Error: Cannot open file web/sitemap.xml');
     }
 }
コード例 #25
0
ファイル: Local.php プロジェクト: 0hyeah/yurivn
 /**
  * Upload an image to local server then return new image path after upload success
  * 
  * @param array $file [tmp_name, name, error, type, size] 
  * @param string image path for saving (this may constain filename)
  * @param string image filename for saving
  * @return string Image path after uploaded
  * @throws Exception If upload failed
  */
 public function upload($file, $newImagePath = '.', $newImageName = NULL)
 {
     if (!empty($file['error'])) {
         $this->_throwException(':method: Upload error. Number: :number', array(':method' => __METHOD__, ':number' => $file['error']));
     }
     if (getimagesize($file['tmp_name']) === FALSE) {
         $this->_throwException(':method: The file is not an image file.', array(':method' => __METHOD__));
     }
     $fileInfo = new \SplFileInfo($newImagePath);
     if (!$fileInfo->getRealPath() or !$fileInfo->isDir()) {
         $this->_throwException(':method: The ":dir" must be a directory.', array(':method' => __METHOD__, ':dir' => $newImagePath));
     }
     $defaultExtension = '.jpg';
     if (empty($newImageName)) {
         if (!in_array($fileInfo->getBasename(), array('.', '..')) and $fileInfo->getExtension()) {
             $newImageName = $fileInfo->getBasename();
         } else {
             $newImageName = uniqid() . $defaultExtension;
         }
     }
     if (!$fileInfo->isWritable()) {
         $this->_throwException(':method: Directory ":dir" is not writeable.', array(':method' => __METHOD__, ':dir' => $fileInfo->getRealPath()));
     }
     $destination = $fileInfo->getRealPath() . DIRECTORY_SEPARATOR . $newImageName;
     if (move_uploaded_file($file['tmp_name'], $destination)) {
         return $destination;
     } else {
         $this->_throwException(':method: Cannot move uploaded file to :path', array(':method' => __METHOD__, ':path' => $fileInfo->getRealPath()));
     }
 }
コード例 #26
0
 protected function createTransferAction(\SplFileInfo $file)
 {
     // Open the file for reading
     $filename = $file->getPathName();
     if (!($resource = fopen($filename, 'r'))) {
         // @codeCoverageIgnoreStart
         throw new RuntimeException("Could not open {$filename} for reading");
         // @codeCoverageIgnoreEnd
     }
     $key = $this->options['source_converter']->convert($filename);
     $body = EntityBody::factory($resource);
     // Determine how the ACL should be applied
     if ($acl = $this->options['acl']) {
         $aclType = is_string($this->options['acl']) ? 'ACL' : 'ACP';
     } else {
         $acl = 'private';
         $aclType = 'ACL';
     }
     // Use a multi-part upload if the file is larger than the cutoff size and is a regular file
     if ($body->getWrapper() == 'plainfile' && $file->getSize() >= $this->options['multipart_upload_size']) {
         $builder = UploadBuilder::newInstance()->setBucket($this->options['bucket'])->setKey($key)->setMinPartSize($this->options['multipart_upload_size'])->setOption($aclType, $acl)->setClient($this->options['client'])->setSource($body)->setConcurrency($this->options['concurrency']);
         $this->dispatch(self::BEFORE_MULTIPART_BUILD, array('builder' => $builder, 'file' => $file));
         return $builder->build();
     }
     return $this->options['client']->getCommand('PutObject', array('Bucket' => $this->options['bucket'], 'Key' => $key, 'Body' => $body, $aclType => $acl));
 }
コード例 #27
0
ファイル: Config.php プロジェクト: qwant50/config
 /**
  * Load config data. Support php|ini|yml config formats.
  *
  * @param string|\SplFileInfo $configFile
  * @throws ConfigException
  */
 public function loadConfig($configFile)
 {
     if (!$configFile instanceof \SplFileInfo) {
         if (!is_string($configFile)) {
             throw new ConfigException('Mismatch type of variable.');
         }
         $path = realpath($this->basePath . $configFile);
         // check basePath at mutation
         if (strpos($configFile, '..') || !strpos($path, realpath($this->basePath))) {
             throw new ConfigException('Config file name: ' . $configFile . ' isn\'t correct.');
         }
         if (!is_file($path) || !is_readable($path)) {
             throw new ConfigException('Config file: ' . $path . ' not found of file isn\'t readable.');
         }
         $configFile = new \SplFileInfo($path);
     }
     $path = $configFile->getRealPath();
     $ext = $configFile->getExtension();
     $key = $configFile->getBasename('.' . $ext);
     if ('php' === $ext) {
         $this->data[$key] = (include $path);
     } elseif ('ini' === $ext) {
         $this->data[$key] = parse_ini_file($path, true);
     } elseif ('yml' === $ext) {
         if (!function_exists('yaml_parse_file')) {
             throw new ConfigException("Function `yaml_parse_file` isn't supported.\n" . 'http://php.net/manual/en/yaml.requirements.php');
         }
         $this->data[$key] = yaml_parse_file($path);
     }
 }
コード例 #28
0
 /**
  * @param \SplFileInfo $file
  */
 public function __construct(\SplFileInfo $file)
 {
     if (!$file->isDir()) {
         throw new \InvalidArgumentException('Expecting directory');
     }
     $this->iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($file->getPathname(), \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS));
 }
コード例 #29
0
 /**
  * todo - добавить проверки и исключения
  * todo - вывести пути в конфиги
  *
  * @param $result
  * @throws \Exception
  */
 protected function postSave($result)
 {
     if (is_array($result)) {
         $data = $this->getData();
         $id = $data['id'];
     } elseif ($result) {
         $id = (int) $result;
     } else {
         $id = 0;
     }
     if (!empty($_FILES['file']['name']) && $id) {
         $configTwigUpload = App::getInstance()->getConfigParam('upload_files');
         if (!isset($configTwigUpload['images_category_and_product'])) {
             throw new \Exception('Неверные Параметры конфигурации upload_files');
         }
         $prefix = $configTwigUpload['images_category_and_product'] . '/category/';
         $uploaddir = App::getInstance()->getCurrDir() . '/web' . $prefix;
         $info = new \SplFileInfo($_FILES['file']['name']);
         $fileExtension = $info->getExtension();
         $uploadfile = $uploaddir . $id . '.' . $fileExtension;
         $uploadfileDB = $prefix . $id . '.' . $fileExtension;
         if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
             $tbl = $this->getDataClass();
             $tbl->update(array('file' => $uploadfileDB), array('id' => $id));
         } else {
             throw new \Exception('Ошибка при сохранении изображения');
         }
     }
 }
コード例 #30
0
 /**
  * @param \SplFileInfo $fileInfo
  * @return mixed|string
  */
 private function getFileExtension(\SplFileInfo $fileInfo)
 {
     if ($fileInfo instanceof UploadedFile) {
         return pathinfo($fileInfo->getClientOriginalName(), PATHINFO_EXTENSION);
     }
     return $fileInfo->getExtension();
 }