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);
 }
 /**
  * upload
  *
  * @param \JInput    $input
  */
 public static function upload(\JInput $input)
 {
     try {
         $editorPlugin = \JPluginHelper::getPlugin('editors', 'akmarkdown');
         if (!$editorPlugin) {
             throw new \Exception('Editor Akmarkdown not exists');
         }
         $params = new Registry($editorPlugin->params);
         $files = $input->files;
         $field = $input->get('field', 'file');
         $type = $input->get('type', 'post');
         $allows = $params->get('Upload_AllowExtension', '');
         $allows = array_map('strtolower', array_map('trim', explode(',', $allows)));
         $file = $files->getVar($field);
         $src = $file['tmp_name'];
         $name = $file['name'];
         $tmp = new \SplFileInfo(JPATH_ROOT . '/tmp/ak-upload/' . $name);
         if (empty($file['tmp_name'])) {
             throw new \Exception('File not upload');
         }
         $ext = pathinfo($name, PATHINFO_EXTENSION);
         if (!in_array($ext, $allows)) {
             throw new \Exception('File extension now allowed.');
         }
         // Move file to tmp
         if (!is_dir($tmp->getPath())) {
             \JFolder::create($tmp->getPath());
         }
         if (is_file($tmp->getPathname())) {
             \JFile::delete($tmp->getPathname());
         }
         \JFile::upload($src, $tmp->getPathname());
         $src = $tmp;
         $dest = static::getDest($name, $params->get('Upload_S3_Subfolder', 'ak-upload'));
         $s3 = new \S3($params->get('Upload_S3_Key'), $params->get('Upload_S3_SecretKey'));
         $bucket = $params->get('Upload_S3_Bucket');
         $result = $s3::putObject(\S3::inputFile($src->getPathname(), false), $bucket, $dest, \S3::ACL_PUBLIC_READ);
         if (is_file($tmp->getPathname())) {
             \JFile::delete($tmp->getPathname());
         }
         if (!$result) {
             throw new \Exception('Upload fail.');
         }
     } catch (\Exception $e) {
         $response = new Response();
         $response->setBody(json_encode(['error' => $e->getMessage()]));
         $response->setMimeType('text/json');
         $response->respond();
         exit;
     }
     $return = new \JRegistry();
     $return['filename'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
     $return['file'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
     $response = new Response();
     $response->setBody((string) $return);
     $response->setMimeType('text/json');
     $response->respond();
 }
Example #3
0
 /**
  * Writes the class to a file.
  */
 public function write()
 {
     try {
         $dir = $this->path->isDir() ? $this->path->getPathname() : $this->path->getPath();
         $path = $dir . '/' . $this->baseClass->getClassName() . $this->baseClass->getExtension();
         if (!file_exists($dir)) {
             $this->fileSystem->mkdir($dir, 0777, true);
         }
         //if (!file_exists($path)) {
         file_put_contents($path, $this->baseClass->generate());
         //}
     } catch (IOExceptionInterface $e) {
     }
 }
Example #4
0
 /**
  * processes the command line arguments
  *
  * @param array $args
  * @return void
  */
 protected function _processArgs($args = array())
 {
     if (count($args) == 1) {
         throw new Exception('no test directory specified');
     }
     $dir = array_pop($args);
     if (!is_dir($dir) && !file_exists($dir)) {
         throw new Exception('invalid test directory specified: ' . $dir);
     }
     // single file
     if (!is_dir($dir) && file_exists($dir)) {
         $path = $this->_convertDirectoryToPath($dir);
         $this->_file = new \SplFileInfo($path);
         $this->directory($this->_file->getPath());
     }
     if (is_dir($dir)) {
         $directory = $this->_convertDirectoryToPath($dir);
         $this->directory($directory);
     }
     $coverage_directory = $this->_getArgValue('--coverage-html', $args);
     if (!$coverage_directory) {
         return;
     }
     if (!file_exists($coverage_directory)) {
         mkdir($coverage_directory);
     }
     $path = $this->_convertDirectoryToPath($coverage_directory);
     $this->coverageDirectory($path);
 }
 /**
  * Extract the zip archive to be imported
  *
  * @throws \RuntimeException When archive cannot be opened or extracted or does not contain exactly one file file
  */
 protected function extractZipArchive()
 {
     $archive = new \ZipArchive();
     $status = $archive->open($this->filePath);
     if (true !== $status) {
         throw new \RuntimeException(sprintf('Error "%d" occurred while opening the zip archive.', $status));
     }
     $path = $this->fileInfo->getPath();
     $filename = $this->fileInfo->getBasename('.' . $this->fileInfo->getExtension());
     $targetDir = sprintf('%s/%s', $path, $filename);
     if (!$archive->extractTo($targetDir)) {
         throw new \RuntimeException('Error occurred while extracting the zip archive.');
     }
     $archive->close();
     $this->archivePath = $targetDir;
     $finder = new Finder();
     $files = $finder->in($targetDir)->name('/\\.' . $this->type . '$/i');
     $count = $files->count();
     if (1 !== $count) {
         throw new \RuntimeException(sprintf('Expecting the root directory of the archive to contain exactly 1 file file, found %d', $count));
     }
     $filesIterator = $files->getIterator();
     $filesIterator->rewind();
     $this->filePath = $filesIterator->current()->getPathname();
 }
Example #6
0
 /**
  * Class constructor
  *
  * @param  string  $file_name  File name
  */
 public function __construct($file_name)
 {
     // Construct a new SplFileInfo object
     $spl = new SplFileInfo($file_name);
     $this->_name = $spl->getBasename();
     $this->_path = $spl->getPath();
     self::$instance = $this;
 }
Example #7
0
 public function buildElephantFile($file)
 {
     $file = new \SplFileInfo($file);
     $resultFile = $file->getPath() . DIRECTORY_SEPARATOR . $file->getBasename('.elph') . '.php';
     $rewriter = new Rewriter($resultFile);
     $rewriter->save();
     return $resultFile;
 }
Example #8
0
 /**
  * Returns the details about Communicator (current) file
  * w/o any kind of verification of file existance
  *
  * @param string $fileGiven
  * @return array
  */
 protected function getFileDetailsRaw($fileGiven)
 {
     $info = new \SplFileInfo($fileGiven);
     $aFileBasicDetails = ['File Extension' => $info->getExtension(), 'File Group' => $info->getGroup(), 'File Inode' => $info->getInode(), 'File Link Target' => $info->isLink() ? $info->getLinkTarget() : '-', 'File Name' => $info->getBasename('.' . $info->getExtension()), 'File Name w. Extension' => $info->getFilename(), 'File Owner' => $info->getOwner(), 'File Path' => $info->getPath(), 'Name' => $info->getRealPath(), 'Type' => $info->getType()];
     $aDetails = array_merge($aFileBasicDetails, $this->getFileDetailsRawStatistic($info, $fileGiven));
     ksort($aDetails);
     return $aDetails;
 }
 protected function checkDirectory($path)
 {
     $outFile = new \SplFileInfo($path);
     $directory = $outFile->getPath();
     if (!$this->file->exists($directory)) {
         $this->file->makeDirectory($directory, 0777, true);
     }
 }
Example #10
0
 function let(\SplFileInfo $file, Suite $suite)
 {
     $file->getFilename()->willReturn(__FILE__);
     $file->getPath()->willReturn(__DIR__);
     $file->getBasename('.php')->willReturn('SpecSpec');
     $this->beConstructedWith($file, $suite, realpath(__DIR__ . '/../../../../..'));
     $this->shouldHaveType('Funk\\Specification\\Locator\\Iterator\\Spec');
 }
Example #11
0
 /**
  * Only allowed for internal files (on the server)
  *
  * @param string $newOnlyName
  * @throws \UnexpectedValueException if the file is link
  * @return bool
  */
 public function rename($newOnlyName)
 {
     if ($this->file->isFile() === false) {
         throw new \UnexpectedValueException('the file can not be link');
     }
     $this->setPath($this->file->getPath());
     $this->setName($newOnlyName);
     return rename($this->file->getRealPath(), $this->fullPath);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $this->processConfiguration($configuration, $configs);
     $reflection = new \ReflectionClass($this);
     $splFile = new \SplFileInfo($reflection->getFileName());
     $loader = new Loader\YamlFileLoader($container, new FileLocator($splFile->getPath() . '/../Resources/config'));
     $loader->load('services.yml');
 }
 /**
  * @param string $filePath
  * @throws InvalidArgumentException
  */
 public function setFilePath($filePath)
 {
     $this->fileInfo = new \SplFileInfo($filePath);
     $dirInfo = new \SplFileInfo($this->fileInfo->getPath());
     if (!$dirInfo->isDir()) {
         throw new InvalidArgumentException(sprintf('Directory "%s" does not exists.', $this->fileInfo->getPath()));
     } elseif (!$dirInfo->isWritable()) {
         throw new InvalidArgumentException(sprintf('Directory "%s" is not writable.', $dirInfo->getRealPath()));
     }
 }
 public function getContent()
 {
     $info = new \SplFileInfo($this->file);
     $renderer = new PhpRenderer();
     $stack = new TemplatePathStack();
     $stack->addPath($info->getPath());
     $stack->setDefaultSuffix(pathinfo($this->file, PATHINFO_EXTENSION));
     $renderer->setResolver($stack);
     return $renderer->render($info->getBasename());
 }
Example #15
0
 /**
  * createThumb
  *
  * @param string $src
  *
  * @return  bool
  */
 public static function createThumb($src, $width = 400, $height = 400)
 {
     $dest = new \SplFileInfo(WINDWALKER_CACHE . '/image/temp/' . md5($src));
     Folder::create($dest->getPath());
     $image = new Image();
     $image->loadFile($src);
     $image->cropResize($width, $height, false);
     $image->toFile($dest->getPathname() . '.jpg');
     return $dest->getPathname() . '.jpg';
 }
Example #16
0
 protected function putFile($file_name, $file_contents)
 {
     $file = new \SplFileInfo($file_name);
     //        if (File::exists($file_name)) {
     //            $answer = $this->confirm($file->getFilename() . ' already exists, would you like to overwrite it?');
     //            if (!$answer) {
     //                return false;
     //            }
     //        }
     if (!File::isDirectory($file->getPath())) {
         File::makeDirectory($file->getPath(), 0755, true);
     }
     try {
         file_put_contents($file_name, $file_contents);
     } catch (\ErrorException $e) {
         $this->error('File could not be saved');
         die;
     }
     return true;
 }
Example #17
0
 public function beforeDelete()
 {
     foreach ($this->photo as $value) {
         $item = SiteImage::FindByPk($value->Pk);
         $this->deleteImage($item);
         $item->delete();
     }
     $tmp = new \SplFileInfo(ROOT_PATH_PUBLIC . $item->image);
     rmdir($tmp->getPath());
     return parent::beforeDelete();
 }
 private function getResourceFile($className)
 {
     $reflection = new \ReflectionClass($className);
     $fileInfo = new \SplFileInfo($reflection->getFileName());
     $file = $fileInfo->getPath() . "/" . $this->file;
     if (file_exists($file)) {
         return $file;
     }
     if (get_parent_class($className) != false) {
         return $this->getResourceFile(get_parent_class($className));
     }
     return null;
 }
Example #19
0
 /**
  * Validate file permissions
  *
  * Checks to see if file permissions match correctly
  *
  * @param SplFileInfo $file     File to check
  * @param array       $badFiles current array of bad files to report
  *
  * @return array
  * @access public
  */
 public function validateSetting(SplFileInfo $file, array $badFiles)
 {
     if ($file->isFile()) {
         $path = substr_replace($file->getPath(), '', 0, strlen(Mage::getBaseDir()) + 1);
         $filepath = substr_replace($file->__toString(), '', 0, strlen(Mage::getBaseDir()) + 1);
         if (Mage::helper('bronto_verify/permissionchecker')->accept($path) && Mage::helper('bronto_verify/permissionchecker')->accept($filepath)) {
             $octalPerms = substr(sprintf('%o', $file->getPerms()), -$this->_permLen);
             if ($octalPerms != $this->_permission) {
                 $badFiles[$filepath]['file permission'] = $octalPerms;
             }
         }
     }
     return parent::validateSetting($file, $badFiles);
 }
 /**
  * @param null $bundle not implemented
  * @param null $type   not implemented
  * @throws \Exception
  */
 public function exportJsonFile($bundle = null, $type = null)
 {
     $json = $this->buildJson($bundle, $type);
     $info = new \SplFileInfo($this->kernelRoot . '/../' . trim($this->exportJsonFile, '\\/'));
     $path = $info->getPath();
     if (!is_dir($path)) {
         if (!mkdir($path, 0770, true)) {
             throw new InvalidPathException('Can\'t create dir: ' . $path);
         }
     }
     if (!file_put_contents($info->getPathname(), $json)) {
         throw new \Exception('File is not writable: ' . $this->exportJsonFile);
     }
 }
Example #21
0
 /**
  * Returns processed file path
  *
  * @param string $fileName
  * @param string $relatedClassName
  * @param string $type
  * @return string|bool
  */
 protected function _getFilePath($fileName, $relatedClassName, $type)
 {
     $reflection = EcomDev_Utils_Reflection::getReflection($relatedClassName);
     $fileObject = new SplFileInfo($reflection->getFileName());
     $basePath = $fileObject->getPath();
     // While base path is within a base directory of Magento installment
     while (strpos($basePath, Mage::getBaseDir()) && !is_dir($basePath . DS . $type)) {
         $basePath = dirname($basePath);
     }
     if (basename($basePath)) {
         return $basePath . DS . $type . DS . $fileName;
     }
     return false;
 }
 /**
  *
  * @return multitype:\SplFileInfo \Symfony\Component\Finder\Finder
  *         \Symfony\Component\HttpFoundation\mixed
  */
 protected function getModel()
 {
     // $model = new Model();
     $model = array();
     $request = $this->getRequest();
     $model['request'] = $request;
     $model['currentRoute'] = $request->get('_route');
     $path = $request->get('path', '');
     $rootDir = $this->get('kernel')->getRootDir();
     $rootDirInfo = new \SplFileInfo($rootDir);
     $filesystemPath = sprintf("%s/%s", $rootDirInfo->getPath(), $path);
     $filesystemInfo = new \SplFileInfo($filesystemPath);
     // $pathInfo->getPathname()
     $model['path'] = $path;
     $model['filesystemPath'] = $filesystemPath;
     $model['filesystemPathInfo'] = $filesystemInfo;
     if (is_dir($filesystemPath)) {
         $model['finder'] = $this->getFinder($filesystemPath);
     } else {
         $source = file_get_contents($filesystemPath);
         $extention = $filesystemInfo->getExtension();
         $language = $filesystemInfo->getExtension();
         switch ($language) {
             case '':
                 $language = "txt";
                 break;
             case 'js':
                 $language = "javascript";
                 break;
             case 'yml':
                 $language = "yaml";
                 break;
             case 'xmi':
             case 'xsd':
             case 'wsdl':
                 $language = "xml";
                 break;
         }
         $geshi = new \GeSHi($source, $language);
         $model['highlight'] = $geshi->parse_code();
         $model['source'] = $source;
     }
     return array('model' => $model);
 }
Example #23
0
 public function createOutFile(File $response)
 {
     $filename = $response->getFilename();
     if ($filename == null) {
         throw new CurlFileException('The target filename of the response is null');
     }
     $outFileInfo = new \SplFileInfo($filename);
     $parentDir = new \SplFileInfo($outFileInfo->getPath());
     if (!$parentDir->isDir()) {
         throw new CurlFileException('The target filename directory does not exist');
     }
     if (!$parentDir->isWritable()) {
         throw new CurlFileException('The target filename directory is not writable');
     }
     if ($outFileInfo->isFile() && !$outFileInfo->isWritable()) {
         throw new CurlFileException('The target filename is not writable');
     }
     $this->fileHandle = \fopen($response->getFilename(), 'w+');
 }
Example #24
0
 /**
  * execute
  *
  * @return  void
  */
 public function execute()
 {
     $this->authenticate();
     $path = $this->getOption('root') . '/tmp/watcher';
     $backupZipFile = new \SplFileInfo($path . '/' . $this->getBackupFilename() . '.zip');
     $backupSQLFile = new \SplFileInfo($path . '/' . $this->getBackupFilename() . '.sql');
     // create folder
     if (!is_dir($path)) {
         if (!mkdir($path, 0755, true)) {
             $this->close('Make dir ' . $path . ' fail.');
         }
     }
     $this->writeHtaccess($backupZipFile->getPath() . '/.htaccess');
     if ($this->getOption('dump_database', true)) {
         $this->dumpSQL($backupSQLFile);
     }
     $this->zipFiles($backupZipFile, $backupSQLFile);
     $this->download($backupZipFile);
 }
 /**
  * Load config file and include imports.
  *
  * @param \SplFileInfo $file
  * @throws InvalidConfigurationException
  * @return array
  */
 protected function loadConfigFile(\SplFileInfo $file)
 {
     $realPathName = $file->getRealPath();
     $configData = Yaml::parse($realPathName);
     if (array_key_exists('imports', $configData) && is_array($configData['imports'])) {
         $imports = $configData['imports'];
         unset($configData['imports']);
         foreach ($imports as $importData) {
             if (array_key_exists('resource', $importData)) {
                 $resourceFile = new \SplFileInfo($file->getPath() . DIRECTORY_SEPARATOR . $importData['resource']);
                 if ($resourceFile->isReadable()) {
                     $includedData = $this->loadConfigFile($resourceFile);
                     $configData = array_merge_recursive($configData, $includedData);
                 } else {
                     throw new InvalidConfigurationException(sprintf('Resource "%s" is unreadable', $resourceFile->getBasename()));
                 }
             }
         }
     }
     return $configData;
 }
Example #26
0
 private static function _getFileInfo($file, $type)
 {
     $fileInfo = new SplFileInfo($file);
     $filePath = $fileInfo->getPath();
     $fileBaseName = $fileInfo->getBasename('.' . $fileInfo->getExtension());
     if (empty($filePath)) {
         $file = $fileBaseName;
     } else {
         $file = $filePath . DIRECTORY_SEPARATOR . $fileBaseName;
     }
     $path = null;
     $baseDir = self::_getBaseDir($type);
     $extNames = $type === 'js' ? self::$_jsExtNames : self::$_cssExtNames;
     foreach ($extNames as $extName) {
         $_path = "{$baseDir}{$file}{$extName}";
         if (file_exists($_path)) {
             $path = $_path;
             break;
         }
     }
     return array($path, str_replace(self::$_serverRootPath, '', $path));
 }
Example #27
0
 private function getProperties(Component $component)
 {
     $target = $component;
     $properties = array();
     while ($target != null) {
         $reflection = new \ReflectionClass($target);
         while ($reflection != null) {
             $fileInfo = new \SplFileInfo($reflection->getFileName());
             $fileName = $fileInfo->getPath() . "/" . $reflection->getShortName() . self::EXTENSION;
             if (file_exists($fileName)) {
                 $loaded = $this->loadProperties($fileName);
                 foreach ($loaded as $name => $value) {
                     if (!array_key_exists($name, $properties)) {
                         $properties[$name] = $value;
                     }
                 }
             }
             $reflection = $reflection->getParentClass();
         }
         $target = $target->getParent();
     }
     return $properties;
 }
Example #28
0
 /**
  * Return array of all possible configurations contained in the config file,
  * one simple file can be converted to multiple configurations
  * when `finders` is used.
  *
  * @param \SplFileInfo   $configFile file containing the configuration, *.yml
  * @param InputInterface $input      command line input, used to override some configuration in the file using command line
  *
  * @return array|Config[]
  */
 public static function createFromConfigFile(\SplFileInfo $configFile, InputInterface $input = null)
 {
     $configArray = Yaml::parse(file_get_contents($configFile->getRealPath()));
     $workingDir = $configFile->getPath();
     if (isset($configArray['finder'])) {
         $configArray['finders'][] = $configArray['finder'];
         unset($configArray['finder']);
     }
     if (!isset($configArray['finders'])) {
         throw new \LogicException('Invalid configuration, configure at least one `finder` node.');
     }
     $configs = [];
     foreach ($configArray['finders'] as $finder) {
         $config = array_merge($configArray, ['finder' => $finder]);
         unset($config['finders']);
         $configs[] = self::parseConfigArray($config, $workingDir);
     }
     if ($input) {
         foreach ($configs as $config) {
             if ($source = self::getSource($input)) {
                 self::overrideConfigSource($config, $source);
             }
         }
     }
     return $configs;
 }
 /**
  * Returns the composer.json contents as array
  *
  * @param boolean $graceful If set to TRUE no exception will be thrown if a JSON file couldn't be read
  * @return array
  * @throws \DomainException if a JSON file couldn't be read
  */
 public function getComposerJson($graceful = FALSE)
 {
     if (!$this->composerJson) {
         $jsonData = array();
         $composerFiles = $this->getComposerFiles();
         foreach ($composerFiles as $package => $composerFilePath) {
             $composerFile = new \SplFileInfo($composerFilePath);
             $relativeComposerFilePath = '../../../../../../' . str_replace(PATH_site, '', $composerFile->getPath());
             #$relativeComposerFilePath = dirname($composerFilePath) . '/';
             $currentJsonData = NULL;
             $jsonString = file_get_contents($composerFilePath);
             if ($jsonString) {
                 $currentJsonData = json_decode($jsonString, TRUE);
             }
             if (!$currentJsonData && !$graceful) {
                 throw new \DomainException('Exception while parsing composer file ' . $composerFilePath . ': ' . $this->getJsonErrorDescription(), 1356356009);
             }
             // Merge the autoload
             if (isset($currentJsonData['autoload']) && is_array($currentJsonData['autoload'])) {
                 foreach ($currentJsonData['autoload'] as $autoloadType => $autoLoadConfig) {
                     switch ($autoloadType) {
                         case 'classmap':
                         case 'psr-0':
                         case 'files':
                             foreach ($autoLoadConfig as $pathKey => $pathOrFile) {
                                 $autoLoadConfig[$pathKey] = $relativeComposerFilePath . $pathOrFile;
                             }
                             $currentJsonData['autoload'][$autoloadType] = $autoLoadConfig;
                             break;
                         default:
                             throw new \DomainException('Exception while adjusting autoload paths in' . $composerFilePath . ': unknown type "' . $autoloadType . '"');
                     }
                 }
             }
             $jsonData[$package] = $currentJsonData;
         }
         $this->composerJson = $jsonData;
     }
     return $this->composerJson;
 }
Example #30
0
<?php

/**
 * Part of Ezset project.
 *
 * @copyright  Copyright (C) 2015 {ORGANIZATION}. All rights reserved.
 * @license    GNU General Public License version 2 or later;
 */
defined('_JEXEC') or die;
$session = JFactory::getSession();
$session->checkToken() or die;
$input = JFactory::getApplication()->input;
$content = $input->getString('content');
$client = $input->get('client', 'site');
$file = $client == 'site' ? 'custom.css' : 'custom-admin.css';
$file = new SplFileInfo(EZSET_FRONT . '/css/' . $file);
if (!is_file($file->getPath())) {
    JFolder::create($file->getPath());
}
file_put_contents($file->getPathname(), $content);
$response = new \Windwalker\View\Json\JsonBuffer(array('file' => $file->getPathname()), JText::_('PLG_SYSTEM_EZSET_SAVE_SUCCESS'));
header('Content-Type: text/json');
echo $response;