public function register($fileinfo)
 {
     //parse module
     if (!$fileinfo instanceof \SplFileInfo) {
         $fileinfo = new \SplFileInfo($fileinfo);
     }
     echo sprintf("scan module %s in folder %s\n", $fileinfo->getFilename(), $fileinfo->getPathname());
     $info_filename = $fileinfo->getPathname() . DIRECTORY_SEPARATOR . 'module.info';
     $module_info = parse_ini_file($info_filename);
     if (!isset($module_info['c_name'])) {
         $module_info['c_name'] = $fileinfo->getFilename();
     }
     $dbal = DBAL::insert(\ORC\APP\Module::TABLENAME_MODULE);
     $dbal->set('name', $module_info['name']);
     $dbal->set('c_name', $module_info['c_name']);
     $dbal->set('description', empty($module_info['description']) ? '' : $module_info['description']);
     $dbal->set('dependence', empty($module_info['dependence']) ? '' : implode(',', $module_info['dependence']));
     //$dbal->set('permissions', empty($module_info['permissions']) ? '' : implode(',', $module_info['permissions']));
     $dbal->setDuplicate(array('name', 'description', 'dependence'));
     $dbal->execute();
     echo "\tdb done.\n";
     if (!empty($module_info['permissions'])) {
         $dbal = DBAL::insert(\ORC\APP\Module::TABLENAME_PERMS);
         foreach ($module_info['permissions'] as $perm) {
             $dbal->set('perm', $perm);
             $dbal->setDuplicate('perm');
             $dbal->execute();
         }
         echo "\tpermission done.\n";
     }
     //check actions
     $folder = $fileinfo->getPathname() . DIRECTORY_SEPARATOR . 'actions';
     $this->scanActions($module_info['c_name'], $folder);
 }
Example #2
0
 public function importSingleMovie(\SplFileInfo $source)
 {
     if (!$source->isReadable()) {
         return $this->output->writelnError(sprintf("File %s not readable", $source->getFilename()));
     }
     $this->output->writelnInfo(sprintf("Importing %s ...", $source->getRealPath()));
     $file = $source->openFile();
     /** @var Movies $movie */
     $movie = $this->getMovie($file->fread($file->getSize()), $file->getBasename('.html'));
     if (!$movie) {
         return $this->output->writelnError(sprintf("Not found dmm id", $source->getFilename()));
     }
     $this->currentDmmId = $movie->banngo;
     if (Movies::findFirstById($movie->id)) {
         return $this->output->writelnWarning(sprintf("Movie %s already exists, insert skipped", $movie->banngo));
     }
     /** @var Mysql $db */
     $db = $this->getDI()->get('dbMaster');
     $db->begin();
     if (false === $movie->save()) {
         $db->rollback();
         return $this->output->writelnError(sprintf("Movie saving failed by %s", implode(',', $movie->getMessages())));
     }
     $db->commit();
     $this->output->writelnSuccess(sprintf("Movie %s saving success as %s, detail: %s", $movie->banngo, $movie->id, ''));
 }
Example #3
0
 public function move($path)
 {
     $newLocation = rtrim($path, '/\\') . DIRECTORY_SEPARATOR . $this->file->getFilename();
     if (false === rename($this->file->getPathname(), $newLocation)) {
         throw new \RuntimeException('The file can not be moved');
     }
     $this->unlinkOnDestroy = false;
     return new \SplFileInfo($newLocation);
 }
Example #4
0
 /**
  * @param string $file
  * @param string $type
  * @param NULL|string $info
  * @throws iDefendFileNotFoundException
  */
 public function __construct($file, $type = self::DEFAULT_TYPE, $info = NULL)
 {
     if (!file_exists($file)) {
         throw new iDefendFileNotFoundException("File {$file} does not exists");
     }
     $this->fileInfo = new \SplFileInfo($file);
     $this->filename = $this->fileInfo->getFilename();
     $this->type = $type;
     $this->info = $info;
 }
Example #5
0
 protected static function isIgnored(\SplFileInfo $file, $ignore)
 {
     if (in_array($file->getFilename(), static::$IGNORED)) {
         return true;
     }
     if ($file->isDir() && in_array($file->getFilename(), $ignore['folders'])) {
         return true;
     }
     if (!$file->isDir() && in_array($file->getFilename(), $ignore['files'])) {
         return true;
     }
     return false;
 }
 public function info()
 {
     if (!isset($this->info)) {
         $this->info = new StorageInfo(array('name' => $this->file->getFilename(), 'hash' => $this->isReadable() ? $this->getHash() : null, 'format' => $this->getFormat(), 'size' => $this->isReadable() ? $this->file->getSize() : 0, 'count' => $this->isReadable() ? count($this->reader()) : 0));
     }
     return $this->info;
 }
 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');
 }
Example #8
0
 public function __construct($path, $source = null)
 {
     if (!file_exists($path)) {
         throw new \Exception("{$path} file Not Found");
     }
     $this->time_create = time();
     $this->name = session_id() . '_' . md5($path);
     $file = new \SplFileInfo($path);
     $this->file_name_no_extension = str_replace('.' . $file->getExtension(), '', $file->getFilename());
     $this->type = $file->getExtension();
     $this->file_name = $file->getFilename();
     $this->path = $path;
     $this->dir = dirname($path);
     $this->modefy = $file->getMTime();
     $this->source = $source;
 }
Example #9
0
 public function deployProcess(\SplFileInfo $file, $name = NULL)
 {
     $builder = new DeploymentBuilder($name === NULL ? $file->getFilename() : $name);
     $builder->addExtensions($file->getExtension());
     $builder->addResource($file->getFilename(), $file);
     return $this->deploy($builder);
 }
 /**
  * {@inheritdoc}
  */
 public function loadMessages(\SplFileInfo $file, $locale, $domain, $format = null)
 {
     $format = $format ?: $file->getExtension();
     if (!isset($this->loaders[$format])) {
         throw new \InvalidArgumentException(sprintf('Unable to import file %s: ' . 'there is no loader associated with format "%s".', $file->getFilename(), $format));
     }
     return $this->loaders[$format]->load($file->getPathname(), $locale, $domain);
 }
 /**
  * Returns extension of file
  *
  * @return string $extension or null if file has no extension
  */
 public function getExtension()
 {
     $extension = pathinfo(parent::getFilename(), PATHINFO_EXTENSION);
     if (!empty($extension)) {
         return $extension;
     }
     return null;
 }
Example #12
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;
 }
Example #13
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 #14
0
 public function testCreateFromDataAndSpec()
 {
     $specName = $this->getFaker()->word;
     $spec = new FileSpec('', array(), 0, "\n");
     $this->specLoader->shouldReceive('loadSpec')->once()->with($specName)->andReturn($spec);
     $file = new \SplFileInfo(__DIR__ . '/../Fixtures/fixed_width.txt');
     $lines = explode("\n", file_get_contents($file->getRealPath()));
     $this->assertEquals(new InMemoryFile($file->getFilename(), strlen($lines[0]), $lines, "\n"), $this->factory->createFromFileAndSpec($file, $specName));
 }
Example #15
0
 /**
  * create file from SplFileInfo
  *
  * @param SplFileInfo $file 
  * @return Post
  */
 private function createFileFromFileInfo(\SplFileInfo $file)
 {
     $post = new Post($this->getFilter());
     $post->setText(file_get_contents((string) $file));
     $post->setIdentifier(str_replace('.markdown', '', $file->getFilename()));
     $post->setCreated($file->getCTime());
     $post->setModified($file->getMTime());
     $matches = array();
     $found = preg_match('/#.*/', $post->getText(), $matches);
     if ($found === false) {
         $title = $file->getFilename();
     } else {
         $title = ltrim(array_shift($matches), '#');
     }
     $post->setTitle($title);
     //parse title out of body text
     return $post;
 }
Example #16
0
 public function __construct($filename)
 {
     $file = new \SplFileInfo($filename);
     $this->filename = $filename;
     if (file_exists($file->getRealPath())) {
         @unlink($file->getRealPath());
     }
     $this->phar = new \Phar($file->getPathname(), 0, $file->getFilename());
 }
 /**
  * @param string $filename
  * @param string $mimeType
  * @return Blob
  * @throws NuxeoClientException
  */
 public static function fromFile($filename, $mimeType)
 {
     $fileInfo = new \SplFileInfo($filename);
     if ($fileInfo->isReadable()) {
         return new Blob($fileInfo->getFilename(), $fileInfo, $mimeType);
     } else {
         throw NuxeoClientException::fromPrevious(new NoSuchFileException($filename));
     }
 }
Example #18
0
 /**
  * Interpolates a string by substituting tokens in a string
  * 
  * Default interpolations:
  * - `:webroot` Path to the webroot folder
  * - `:model` The current model e.g images
  * - `:field` The database field
  * - `:filename` The filename
  * - `:extension` The extension of the file e.g png
  * - `:id` The record id
  * - `:style` The current style e.g thumb
  * - `:hash` Generates a hash based on the filename
  * 
  * @param string $string The string to be interpolated with data.
  * @param string $name The name of the model e.g. Image
  * @param int $id The id of the record e.g 1
  * @param string $field The name of the database field e.g file
  * @param string $style The style to use. Should be specified in the behavior settings.
  * @param array $options You can override the default interpolations by passing an array of key/value
  *              pairs or add extra interpolations. For example, if you wanted to change the hash method
  *              you could pass `array('hash' => sha1($id . Configure::read('Security.salt')))`
  * @return array Settings array containing interpolated strings along with the other settings for the field.
  */
 public static function run($string, $name, $id, $field, $filename, $style = 'original', $data = array())
 {
     $info = new SplFileInfo($filename);
     $data += array('webroot' => preg_replace('/\\/$/', '', WWW_ROOT), 'model' => Inflector::tableize($name), 'field' => strtolower($field), 'filename' => $info->getBasename($info->getExtension()), 'extension' => $info->getExtension(), 'id' => $id, 'style' => $style, 'hash' => md5($info->getFilename() . Configure::read('Security.salt')));
     foreach (static::$_interpolations as $name => $closure) {
         $data[$name] = $closure($info);
     }
     return String::insert($string, $data);
 }
 public function download()
 {
     $contents = Http::get($_GET["url"]);
     $fileInfo = new SplFileInfo($_GET["fname"]);
     // Add the torrent to deluge using the RPC api
     $tconfig = Storage::get("torrents");
     $client = new HTTPClient((array) $tconfig->deluge);
     $client->core->add_torrent_file($tconfig->dropPath . "/" . $fileInfo->getFilename() . ".torrent", base64_encode($contents), null);
     return $this->redirect("/?alert=" . urlencode("Torrent download started"));
 }
Example #20
0
File: Set.php Project: eexit/smak
 /**
  * Class constructor
  * 
  * @param \SplFileInfo $set_info Set file info
  */
 public function __construct(\SplFileInfo $set_info)
 {
     parent::__construct();
     $this->set_path = $set_info->getRealPath();
     $this->name = $set_info->getFilename();
     $this->files()->in($set_info->getRealPath())->ignoreDotFiles(true);
     foreach ($this->allowed_ext as $ext) {
         $this->name(sprintf('/%s$/i', $ext));
     }
 }
Example #21
0
 /**
  * @param \SplFileInfo $package
  * @return array
  * @throws \movi\FileNotFoundException
  */
 private function getData(\SplFileInfo $package)
 {
     $file = $package->getPathname() . '/' . self::PACKAGE_FILE;
     if (!file_exists($file) || !is_readable($file)) {
         throw new FileNotFoundException("JSON file for package '" . $package->getFilename() . "' was not found or is not readable.");
     }
     $data = Json::decode(file_get_contents($file), Json::FORCE_ARRAY);
     $data['dir'] = $package->getPathname();
     return Arrays::mergeTree($data, $this->defaults);
 }
 /**
  * @param Request $request
  *
  * @return BinaryFileResponse
  *
  * @throws HttpException
  */
 public function downloadAction(Request $request)
 {
     $document = new \SplFileInfo($this->resources . '/' . $request->get('fileName'));
     if (!$document->isReadable()) {
         throw new HttpException(404);
     }
     $response = new BinaryFileResponse($document);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $document->getFilename());
     return $response;
 }
Example #23
0
 public function importXmlFile(\SplFileInfo $source)
 {
     if (!$source->isReadable()) {
         return $this->output->writelnError(sprintf("File %s not readable", $source->getFilename()));
     }
     $this->output->writelnInfo(sprintf("Importing %s ...", $source->getRealPath()));
     $file = $source->openFile();
     $xml = simplexml_load_string($file->fread($file->getSize()));
     return $this->saveDmmList($xml);
 }
 protected function set_liste2File($chemin)
 {
     $liste2File = array();
     $listeTempo = array();
     $listeTempo = scandir($chemin, 0);
     reset($listeTempo);
     next($listeTempo);
     //on passe ..
     while (next($listeTempo) || $this->_stop < 4) {
         //on passe .
         $File = new SplFileInfo(current($listeTempo));
         if (!$File->isDir()) {
             $liste2File[] = $File->getFilename();
         } else {
             $liste2File[] = array($this->set_liste2DirBrute($File->getFilename()));
         }
         $this->_stop++;
     }
     return array($chemin, $liste2File);
 }
Example #25
0
 public function loadMigrationsFromDirectory($dir)
 {
     foreach (glob($dir . DIRECTORY_SEPARATOR . '*.php') as $file) {
         $file = new \SplFileInfo($file);
         $m = NULL;
         if ($file->isFile() && preg_match("'^(Version([0-9]{14}))\\.php\$'i", $file->getFilename(), $m)) {
             $this->migrations[$m[2]] = realpath($file->getPathname());
         }
     }
     ksort($this->migrations);
 }
Example #26
0
 private function isFileChanged(\SplFileInfo $file, &$previously)
 {
     $name = $file->getFilename();
     $mtime = $file->getMTime();
     if (isset($previously[$name])) {
         $changed = $previously[$name]['mtime'] != $mtime;
     } else {
         $changed = true;
     }
     $previously[$name] = array('mtime' => $mtime);
     return $changed;
 }
 /**
  * Generate all the path data of a file. If the original file name exceeds 100 characters, it is truncated.
  * The file name is sanitized, and a unique ID is prepended.
  *
  * For example, a file called "this i#s the é file.txt'" will produce the following output:
  *   [
  *      'uuid'      => '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12',
  *      'file_name' => '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12_this_i_s_the___file.txt'
  *      'path'      => '2/f/d/4/',
  *      'path_name' => '2/f/d/4/2fd4e1c67a2d28fced849ee1bb76e7391b93eb12_this_i_s_the___file.txt',
  *   ]
  *
  * @param \SplFileInfo $file
  *
  * @return array
  */
 public function generate(\SplFileInfo $file)
 {
     $originalFileName = $file instanceof UploadedFile ? $file->getClientOriginalName() : $file->getFilename();
     $uuid = $this->generateUuid($originalFileName);
     $sanitized = preg_replace('#[^A-Za-z0-9\\.]#', '_', $originalFileName);
     if (strlen($sanitized) > 100) {
         $sanitized = sprintf('%s.%s', substr($sanitized, 0, 95), $file->getExtension());
     }
     $fileName = $uuid . '_' . $sanitized;
     $path = sprintf('%s/%s/%s/%s/', $uuid[0], $uuid[1], $uuid[2], $uuid[3]);
     $pathName = $path . $fileName;
     return ['uuid' => $uuid, 'file_name' => $fileName, 'path' => $path, 'path_name' => $pathName];
 }
Example #28
0
 /**
  * load languages
  */
 private function _loadLanguage()
 {
     $i18nCfg = ConfigHandler::get('i18n');
     if (!$i18nCfg['enable']) {
         return null;
     }
     $current_lang_code = $this->get('lang');
     if (!$current_lang_code) {
         $current_lang_code = Factory::getCookie()->read('language');
     }
     if (!$current_lang_code) {
         $this->currentLang = \Languages::retrieveByDefault(1);
         $current_lang_code = $this->currentLang->getLangCode();
     } else {
         $this->currentLang = \Languages::retrieveByLangCode($current_lang_code);
     }
     if ($current_lang_code) {
         Factory::getCookie()->write('language', $current_lang_code);
     }
     //load message
     $translator = Translator::getInstance();
     $translator->setLocale($current_lang_code);
     if ($translator) {
         $translator->addLoader('yml', new YamlFileLoader());
         if (isset($i18nCfg['resource']) && is_array($i18nCfg['resource'])) {
             foreach ($i18nCfg['resource'] as $locale => $files) {
                 for ($i = 0, $size = sizeof($files); $i < $size; ++$i) {
                     $fileInfo = new \SplFileInfo($files[$i]);
                     $filename = $fileInfo->getFilename();
                     $ext = $fileInfo->getExtension();
                     if ($ext == 'yml') {
                         $domain = str_replace('.' . $fileInfo->getExtension(), '', $fileInfo->getFilename());
                         $translator->addResource('yml', $files[$i], $locale, $domain);
                     }
                 }
             }
         }
     }
 }
Example #29
0
 /**
  * Gets the extension of the file.
  *
  * @return    string
  */
 public function getExtension()
 {
     if (is_null($this->extension) === true) {
         $filename = parent::getFilename();
         $str = new StringWrapper($filename);
         $this->extension = $str->getFirstEndMatch($this->predefinedExtensions);
         $this->hasPredefinedExt = true;
         if ($this->extension === '') {
             $this->hasPredefinedExt = false;
             $this->extension = parent::getExtension();
         }
     }
     return $this->extension;
 }
 public function testInsertFileWithNumericSuffix()
 {
     $user = $this->getUser();
     $file = new \SplFileInfo(TESTS_PATH . self::TEST_FILE3);
     $originalFilename = $file->getFilename();
     $user->setFile($file);
     $this->_em->persist($user);
     $this->_em->flush();
     $path = FILESYSTEM1 . $user->getFileKey();
     $this->assertNotEquals($path, FILESYSTEM1);
     $this->assertTrue(file_exists($path));
     $this->assertTrue($user->getFile() instanceof File);
     $this->assertEquals(basename($user->getFile()->getKey()), $originalFilename);
 }