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)); }
/** * {@inheritdoc} */ public function supports(\SplFileInfo $file) { $path = $file->getPathName(); // some fixtures are auto-generated by Symfony and may contain unused use statements if (false !== strpos($path, DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR) && false === strpos($path, DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR)) { return false; } return true; }
/** * @return array */ public function toArray() { $rows = []; $currentDir = getcwd() . DIRECTORY_SEPARATOR; /* @var $reflection ReflectionFile */ foreach ($this->getIterator() as $reflection) { $row = []; $file = new \SplFileInfo($reflection->getName()); $row = array("Files" => str_replace($currentDir, "", $file->getPathName()), "Owner" => $file->getOwner(), "Group" => $file->getGroup(), "Permissions" => $file->getPerms(), "Created" => date("d.m.Y h:m:s", $file->getCTime()), "Modified" => date("d.m.Y h:m:s", $file->getMTime())); $rows[] = $row; } return $rows; }
protected function registerTables() { $dataTables = $this->allFiles($this->dataBaseDir); foreach ($dataTables as $file) { $spl = new \SplFileInfo($file); if (preg_match(self::REGEXDataTableFileCheck, $spl->getFilename(), $matches)) { if (count($matches) != 3 || $matches[2] != $this->version) { continue; } $this->tables[$matches[1]] = $spl->getPathName(); //NON init } } return $this; }
/** * Find method * * @param string $pattern * @param \SplFileInfo $fileInfo * * @return bool|\SplFileInfo */ public function find($pattern, \SplFileInfo $fileInfo) { if (!is_string($pattern)) { throw new \InvalidArgumentException('Pattern should be an string'); } $pattern = $this->createRegExp($pattern); $data = fopen($fileInfo->getPathName(), 'r'); $return = false; while ($line = fgets($data, 1024)) { if (preg_match($pattern, $line)) { $return = $fileInfo; } } return $return; }
protected function extract(\SplFileInfo $file, $directory) { $fileName = substr($file->getPathName(), strlen($directory) + 1); $extension = $file->getExtension(); $messages = []; foreach ($this->filters[$extension] as $filterName) { $filter = $this->getFilter($filterName); $filterData = $filter->extract($file->getRealPath()); if (!is_array($filterData)) { continue; } $messages = array_merge($messages, $filterData); } echo sprintf('File: %s, messages: %d', $fileName, count($messages)) . "\n"; $this->data[$fileName] = $messages; }
protected function getDatabasesFromSchema(\SplFileInfo $file) { $transformer = new \XmlToAppData(null, null, 'UTF-8'); $config = new \QuickGeneratorConfig(); if (file_exists($propelIni = $this->getContainer()->getParameter('kernel.root_dir') . '/config/propel.ini')) { foreach ($this->getProperties($propelIni) as $key => $value) { if (0 === strpos($key, 'propel.')) { $newKey = substr($key, strlen('propel.')); $j = strpos($newKey, '.'); while (false !== $j) { $newKey = substr($newKey, 0, $j) . ucfirst(substr($newKey, $j + 1)); $j = strpos($newKey, '.'); } $config->setBuildProperty($newKey, $value); } } } $transformer->setGeneratorConfig($config); return $transformer->parseFile($file->getPathName())->getDatabases(); }
/** * Overrides \Drupal\Core\Database\Connection::createDatabase(). * * @param string $database * The name of the database to create. * * @throws \Drupal\Core\Database\DatabaseNotFoundException */ public function createDatabase($database) { // Verify the database is writable. $db_directory = new \SplFileInfo(dirname($database)); if (!$db_directory->isDir() && !drupal_mkdir($db_directory->getPathName(), 0755, TRUE)) { throw new DatabaseNotFoundException('Unable to create database directory ' . $db_directory->getPathName()); } }
/** * Initializes the page instance variables based on a file * * @param \SplFileInfo $file The file information for the .md file that the page represents * @param string $extension */ public function init(\SplFileInfo $file, $extension = null) { $this->filePath($file->getPathName()); $this->modified($file->getMTime()); $this->id($this->modified() . md5($this->filePath())); $this->routable(true); $this->header(); $this->date(); $this->metadata(); $this->url(); $this->visible(); $this->modularTwig($this->slug[0] == '_'); $this->setPublishState(); $this->published(); // some extension logic if (empty($extension)) { $this->extension('.' . $file->getExtension()); } else { $this->extension($extension); } // extract page language from page extension $language = trim(basename($this->extension(), 'md'), '.') ?: null; $this->language($language); }
/** * Initializes the page instance variables based on a file * * @param \SplFileInfo $file The file information for the .md file that the page represents * @param string $extension * * @return $this */ public function init(\SplFileInfo $file, $extension = null) { $config = self::getGrav()['config']; $this->hide_home_route = $config->get('system.home.hide_in_urls', false); $this->home_route = $config->get('system.home.alias'); $this->filePath($file->getPathName()); $this->modified($file->getMTime()); $this->id($this->modified() . md5($this->filePath())); $this->routable(true); $this->header(); $this->date(); $this->metadata(); $this->url(); $this->visible(); $this->modularTwig($this->slug[0] == '_'); $this->setPublishState(); $this->published(); $this->urlExtension(); // some extension logic if (empty($extension)) { $this->extension('.' . $file->getExtension()); } else { $this->extension($extension); } // extract page language from page extension $language = trim(basename($this->extension(), 'md'), '.') ?: null; $this->language($language); return $this; }
private function writeFormType(BundleInterface $bundle, \Table $table, \SplFileInfo $file, $force, OutputInterface $output) { $modelName = $table->getPhpName(); $formTypeContent = file_get_contents(__DIR__ . '/../Resources/skeleton/FormType.php'); $formTypeContent = str_replace('##NAMESPACE##', $bundle->getNamespace() . str_replace('/', '\\', self::DEFAULT_FORM_TYPE_DIRECTORY), $formTypeContent); $formTypeContent = str_replace('##CLASS##', $modelName . 'Type', $formTypeContent); $formTypeContent = str_replace('##FQCN##', sprintf('%s\\%s', $table->getNamespace(), $modelName), $formTypeContent); $formTypeContent = str_replace('##TYPE_NAME##', strtolower($modelName), $formTypeContent); $formTypeContent = $this->addFields($table, $formTypeContent); file_put_contents($file->getPathName(), $formTypeContent); $this->writeNewFile($output, $this->getRelativeFileName($file) . ($force ? ' (forced)' : '')); }
/** * Write a FormType. * * @param BundleInterface $bundle The bundle in which the FormType will be created. * @param Table $table The table for which the FormType will be created. * @param \SplFileInfo $file File representing the FormType. * @param boolean $force Is the write forced? * @param OutputInterface $output An OutputInterface instance. */ protected function writeFormType(BundleInterface $bundle, Table $table, \SplFileInfo $file, $force, OutputInterface $output) { $formBuilder = new FormBuilder(); $formTypeContent = $formBuilder->buildFormType($bundle, $table, self::DEFAULT_FORM_TYPE_DIRECTORY); file_put_contents($file->getPathName(), $formTypeContent); $this->writeNewFile($output, $this->getRelativeFileName($file) . ($force ? ' (forced)' : '')); }
/** * Initializes the page instance variables based on a file * * @param \SplFileInfo $file The file information for the .md file that the page represents * @param string $extension */ public function init(\SplFileInfo $file, $extension = null) { $this->filePath($file->getPathName()); $this->modified($file->getMTime()); $this->id($this->modified() . md5($this->filePath())); $this->header(); $this->date(); $this->metadata(); $this->url(); $this->visible(); $this->modularTwig($this->slug[0] == '_'); $this->setPublishState(); $this->published(); if (empty($extension)) { $this->extension('.' . $file->getExtension()); } else { $this->extension($extension); } }
/** * Creates backup from full path * * @param SplFileInfo $fileinfo * @return Backup * @author : Rafał Trójniak rafal@trojniak.net */ static public function create(\SplFileInfo $fileinfo) { if(!$fileinfo->isDir()){ throw new \RuntimeException('Supplied argument "'.addslashes($fileinfo->getPathName()).'"'. ' is not a directory'); } $name=$fileinfo->getFilename(); $date=\DateTime::createFromFormat(\DateTime::ISO8601,$name); if(! $date instanceof \DateTime){ throw new \RuntimeException('Cannot parse date from file '. $fileinfo->getPathName() .' with format '.\DateTime::ISO8601.' and input '.$name); } return new Backup( $date, $fileinfo->getPathName() ); }
/** * {@inheritDoc} */ public function process(MediaInterface $media, VariantInterface $variant, \SplFileInfo $source = NULL) { $options = $variant->getOptions(); $result = $source; list($originalWidth, $originalHeight) = getimagesize($source->getPathName()); $width = $originalWidth; $height = $originalHeight; if (is_array($options) && !empty($options)) { if ($this->imagine == NULL) { throw new ProviderProcessException(sprintf('Cannot process image "%s": Imagine library not installed or misconfigured', $media), $this, $media, $variant); } $options = $this->processOptions($options, $variant->getName(), $media->getContext()); $destFile = sprintf('%s%s-temp-%s.%s', $this->tempDir, date('Y-m-d-h-i-s'), $source->getBasename('.' . $source->getExtension()), $options['format']); /** * @var \Imagine\Image\ImageInterface $image */ $image = $this->imagine->open($source); if ($options['enlarge'] === TRUE || $originalWidth >= $options['width'] && $originalHeight >= $options['height']) { $width = $options['width']; $height = $options['height']; if ($options['resize'] == 'proportional') { //calculate missing dimension if ($width === NULL) { $width = round($originalWidth * $height / $originalHeight); } elseif ($height === NULL) { $height = round($width * $originalHeight / $originalWidth); } } $box = new \Imagine\Image\Box($width, $height); if ($options['resize'] == 'proportional' || $options['resize'] == 'stretch') { $image->resize($box); } elseif ($options['resize'] == 'crop') { $image = $image->thumbnail($box, \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND); } } $image->save($destFile, array('quality' => $options['quality'])); $this->addTempFile($destFile); $result = new \SplFileInfo($destFile); } //set variant metadata $variant->setMetaValue('size', $result->getSize()); $variant->setMetaValue('width', $width); $variant->setMetaValue('height', $height); return $result; }
protected function addFormType(\SplFileInfo $file, $properties, $namespace, $name) { $content = file_get_contents(__DIR__ . '/../Resources/skeleton/FormType.php'); $content = str_replace('##NAMESPACE##', str_replace('\\Entity', '', $namespace) . str_replace('/', '\\', self::DEFAULT_FORM_TYPE_DIRECTORY), $content); $content = str_replace('##CLASS##', $name . 'Type', $content); $content = str_replace('##FQCN##', sprintf('%s\\%s', $namespace, $name), $content); $content = $this->addFormFields($properties, $content); file_put_contents($file->getPathName(), $content); }
/** * @param \SplFileInfo $file */ protected function getCurrentTraining(\SplFileInfo $file) { $fragment = explode('/', $file->getPathName()); return $fragment[count($fragment) - 3]; }
public function generate($rootDir, $rootNamespace) { if (!is_dir($rootDir)) { throw new \InvalidArgumentException(sprintf('"%s" is not a directory.', $rootDir)); } $rootNamespace = rtrim($rootNamespace, '\\'); $component = new \SplFileInfo($rootDir); // scan files $exceptions = array(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($component->getPathName())) as $file) { if ('.php' !== substr($file->getFileName(), -4)) { continue; } $foundExceptions = array(); // locate exceptions $this->lexer->setInput(file_get_contents($file->getRealPath())); $code = ''; $this->lexer->moveNext(); $useStatements = array(); $fqcn = null; $extends = $implements = $class = null; while (null !== $this->lexer->lookahead) { $this->lexer->moveNext(); if ($this->lexer->token['type'] === T_NEW || $this->lexer->token['type'] === T_USE || $this->lexer->token['type'] === T_EXTENDS || $this->lexer->token['type'] === T_CLASS || $this->lexer->token['type'] === T_IMPLEMENTS) { $start = $this->lexer->token['type']; $fqcn = ''; } else { if ($this->lexer->token['type'] === T_STRING || $this->lexer->token['type'] === T_NS_SEPARATOR) { if (null !== $fqcn) { $fqcn .= $this->lexer->token['value']; continue; } } else { if (null !== $fqcn && '' !== $fqcn) { if ($start === T_NEW) { if (in_array($fqcn, self::$splExceptions)) { $code .= substr($fqcn, 1); $foundExceptions[] = $fqcn; } else { $code .= $fqcn; } } else { if ($start === T_USE) { $code .= $fqcn; $useStatements[] = $fqcn; } else { if ($start === T_EXTENDS) { $extends = $fqcn; $code .= $fqcn; } else { if ($start === T_CLASS) { $class = $fqcn; $code .= $fqcn; } else { if ($start === T_IMPLEMENTS) { $class = $fqcn; $code .= $fqcn; } } } } } } if ($this->lexer->token['type'] !== T_WHITESPACE || $fqcn !== '') { $fqcn = null; } } } $code .= $this->lexer->token['value']; } $this->lexer->setInput($code); $this->lexer->moveNext(); $foundExceptions = array_unique($foundExceptions); $code = ''; if (!$foundExceptions) { continue; } $added = false; $inNamespace = false; while (null !== $this->lexer->lookahead) { $this->lexer->moveNext(); if ($useStatements && $this->lexer->token['type'] === T_USE) { if (!$added) { $added = true; foreach ($foundExceptions as $ex) { $import = $rootNamespace . '\\Exception' . $ex; if (in_array($import, $useStatements)) { continue; } $code .= 'use ' . $import . ";\n"; } } } else { if (!$useStatements && $this->lexer->token['type'] === T_NAMESPACE) { $inNamespace = true; } else { if ($inNamespace && $this->lexer->token['type'] === T_LITERAL && $this->lexer->token['value'] === ';') { $code .= ";\n"; $inNamespace = false; foreach ($foundExceptions as $ex) { $import = $rootNamespace . '\\Exception' . $ex; $code .= "\nuse " . $import . ";"; } continue; } } } $code .= $this->lexer->token['value']; } file_put_contents($file->getRealPath(), $code); $exceptions[] = $foundExceptions; } if (!$exceptions) { return; } $exceptions = call_user_func_array('array_merge', $exceptions); $exceptions = array_unique($exceptions); if (!is_dir($exDir = $component->getPathName() . '/Exception')) { mkdir($exDir); } if (!file_exists($exDir . '/Exception.php')) { ob_start(); include __DIR__ . '/../Resources/skeleton/Exception/Exception.php'; $exTemplate = ob_get_contents(); ob_end_clean(); $exTemplate = str_replace('[?php', '<?php', $exTemplate); file_put_contents($exDir . '/Exception.php', $exTemplate); } foreach ($exceptions as $ex) { if (file_exists($path = $exDir . '/' . substr($ex, 1) . '.php')) { continue; } ob_start(); include __DIR__ . '/../Resources/skeleton/Exception/SPLException.php'; $template = ob_get_contents(); ob_end_clean(); $template = str_replace('[?php', '<?php', $template); file_put_contents($path, $template); } }
/** * Initializes the page instance variables based on a file * * @param \SplFileInfo $file The file information for the .md file that the page represents * @return void */ public function init(\SplFileInfo $file) { $this->filePath($file->getPathName()); $this->modified($file->getMTime()); $this->id($this->modified() . md5($this->filePath())); $this->header(); $this->date(); $this->metadata(); $this->slug(); $this->visible(); $this->modularTwig($this->slug[0] == '_'); // Handle publishing dates if no explict published option set if (self::getGrav()['config']->get('system.pages.publish_dates') && !isset($this->header->published)) { // unpublish if required, if not clear cache right before page should be unpublished if ($this->unpublishDate()) { if ($this->unpublishDate() < time()) { $this->published(false); } else { $this->published(); self::getGrav()['cache']->setLifeTime($this->unpublishDate()); } } // publish if required, if not clear cache right before page is published if ($this->publishDate() != $this->modified() && $this->publishDate() > time()) { $this->published(false); self::getGrav()['cache']->setLifeTime($this->publishDate()); } } $this->published(); }
<?php chdir(__DIR__ . '/../../..'); $info = new SplFileInfo('test/sample_dir'); var_dump($info->getRealPath()); var_dump($info->getPath()); var_dump($info->getPathName()); $info = new SplFileInfo('test/sample_dir/'); var_dump($info->getRealPath()); var_dump($info->getPath()); var_dump($info->getPathName()); $info = new SplFileInfo('test/sample_dir//../sample_dir'); var_dump($info->getRealPath()); var_dump($info->getPath()); var_dump($info->getPathName()); $p = realpath('test'); $info = new SplFileInfo($p . '/sample_dir/symlink'); var_dump($info->getLinkTarget()); var_dump($info->getRealPath()); var_dump($info->getPath()); var_dump($info->getPathName());
/** * Initializes the page instance variables based on a file * * @param \SplFileInfo $file The file information for the .md file that the page represents * @return void */ public function init($file) { $this->filePath($file->getPathName()); $this->modified($file->getMTime()); $this->id($this->modified() . md5($this->filePath())); $this->header(); $this->metadata(); $this->slug(); $this->visible(); $this->modularTwig($this->slug[0] == '_'); }
/** * Checks if the passed directory is the contrib module we are looking for. * * @param \SplFileInfo $dir * The info object about the directory. * @return bool * TRUE if the contrib is detected. FALSE otherwise. */ protected function isWantedContrib(\SplFileInfo $dir) { $info_file = $this->cleanDirPath($dir->getPathName()) . DIRECTORY_SEPARATOR . $this->moduleName . '.info'; return file_exists($info_file); }