/** * Sets the root path * @param File $rootPath The root path * @throws FileSystemException */ private function setRootPath(File $rootPath) { if (!$rootPath->isDirectory()) { throw new FileSystemException('Could not build the index: ' . $this->rootPath->getPath() . ' is not a directory.'); } $this->rootPath = $rootPath; }
/** * Check if a file is supported by this ImageIO. This check is based on the extension. * @param File file to check if it is supported * @param mixed supportedExtensions string of an extension or array with extension strings */ protected function checkIfFileIsSupported(File $file, $supportedExtensions) { if (!$file->hasExtension($supportedExtensions)) { throw new ImageException($file->getPath() . ' is not supported'); } return true; }
/** * Installs the continents from the data directory. The data directory is defined in the orm.path.continents configuration * @param array $locales Array with locale codes * @return array Array with the continent code as key and the continent data as value */ public function installContinents(array $locales) { $path = $this->getDataPath(); $query = $this->createQuery(0); $continents = $query->query('code'); $transactionStarted = $this->startTransaction(); try { foreach ($locales as $locale) { $file = new File($path, $locale . '.ini'); if (!$file->exists()) { continue; } $continentNames = parse_ini_file($file->getPath(), false, INI_SCANNER_RAW); foreach ($continentNames as $continentCode => $continentName) { if (array_key_exists($continentCode, $continents)) { $continent = $continents[$continentCode]; } else { $continent = $this->createData(); $continent->code = $continentCode; $continents[$continentCode] = $continent; } $continent->name = $continentName; $continent->dataLocale = $locale; $this->save($continent); } } $this->commitTransaction($transactionStarted); } catch (Exception $e) { $this->rollbackTransaction($transactionStarted); throw $e; } return $continents; }
public function setUp() { $path = new File(__DIR__ . '/../../../../../'); $this->setUpApplication($path->getPath()); $browser = new GenericBrowser(new File(getcwd())); $configIO = new IniConfigIO(Environment::getInstance(), $browser); Zibo::getInstance($browser, $configIO); }
public function testReadDirectoryWithFilters() { $directoryFilter = new File('filter'); $directorySvn = new File('.svn'); $expected = array($directoryFilter->getPath() => $directoryFilter, $directorySvn->getPath() => $directorySvn); $filter = new DirectoryFilter(); $files = $this->browser->readDirectory(null, array($filter)); $this->assertEquals($expected, $files); }
protected function setUp() { $path = new File(__DIR__ . '/../../../../'); $this->setUpApplication($path->getPath()); $browser = new GenericBrowser(new File(getcwd())); $configIO = new IniConfigIO(Environment::getInstance(), $browser); Zibo::getInstance($browser, $configIO); $validationFactory = ValidationFactory::getInstance(); $validationFactory->registerValidator('email', 'zibo\\library\\mail\\AddressValidator'); }
/** * Gets the file from the Zibo include paths * @param string $path Path, in the webdirectory, of the file * @return null|zibo\library\filesystem\File */ private function getFile($path) { $zibo = Zibo::getInstance(); $plainPath = new File(Zibo::DIRECTORY_WEB . File::DIRECTORY_SEPARATOR . $path); $file = $zibo->getFile($plainPath->getPath()); if ($file) { return $file; } $encodedPath = new File($plainPath->getParent()->getPath(), urlencode($plainPath->getName())); return $zibo->getFile($encodedPath->getPath()); }
/** * During construction, you can specify a path to a file and a file name. This * will prep the File instance for an upload. If you do not wish * to upload a file, simply instantiate this class without any attributes. * * If you want to fill this class with the details of a specific file, then * get_file_info and it will be imported into its own Box_Client_File class. * * @param zibo\library\filesystem\File $file Provide a file if you want to upload a directory or a file * @return null */ public function __construct(File $file = null) { $this->attributes = array(); $this->tags = array(); if ($file) { if ($file->isDirectory) { $this->attribute('localpath', $file->getPath()); } else { $this->attribute('localpath', $file->getParent()->getPath()); $this->attribute('filename', $file->getName()); } } }
/** * Construct a file object * @param string|File $path * @param string|File $child file in the provided path (optional) * @return null * @throws zibo\library\filesystem\exception\FileSystemException when the path is empty * @throws zibo\library\filesystem\exception\FileSystemException when the child is absolute */ public function __construct($path, $child = null) { $this->isRootPath = false; $this->path = self::retrievePath($path, $this->isRootPath); if ($child != null) { $child = new File($child); if ($child->isAbsolute()) { throw new FileSystemException('Child ' . $child->getPath() . ' cannot be absolute'); } $childPath = $child->getPath(); if ($child->hasPharProtocol()) { $childPath = substr($childPath, 7); } if (!$this->isRootPath) { $this->path .= self::DIRECTORY_SEPARATOR; } $this->path .= $childPath; } if ($this->isInPhar() && !$this->hasPharProtocol()) { $this->path = 'phar://' . $this->path; } }
protected function setUp() { $path = new File(__DIR__ . '/../../../../'); $this->setUpApplication($path->getPath()); $browser = new GenericBrowser(new File(getcwd())); $configIO = new IniConfigIO(Environment::getInstance(), $browser); Zibo::getInstance($browser, $configIO); if (!DatabaseManager::getInstance()->hasConnection('mysql')) { $this->markTestSkipped('No dsn found for database.connection.mysql, check config/database.ini'); } $this->manager = ModelManager::getInstance(); Reflection::setProperty($this->manager, 'models', array()); }
public function testWriteModules() { $smarty = new Module('zibo', 'smarty', '1.0.0'); $xml = new Module('zibo', 'xml', '1.0.0'); $admin = new Module('zibo', 'admin', '0.1.0', '0.1.0', array($smarty, $xml)); $xml = new Module('zibo', 'xml', '1.0.0', '0.1.0'); $modules = array('zibo' => array('admin' => $admin, 'xml' => $xml)); $path = new File('application/data'); $io = new XmlModuleIO(); $io->writeModules($path, $modules); $file = new File($path, XmlModuleIO::MODULE_FILE); $this->assertXmlFileEqualsXmlFile('application/config/module.xml', $file->getPath()); }
/** * Reads from the filesystem with extra options * @param zibo\library\filesystem\File $path The path of the directory to read * @param array $filters Array with filters * @param boolean $recursive Set to true to read recursivly * @return array Array with the directories and files of the provided path */ public function readDirectory(File $path = null, array $filters = array(), $recursive = false) { $path = new File($this->root, $path); if (!$path->exists()) { throw new FileSystemException($path->getPath() . ' does not exist'); } if (!$path->isDirectory()) { throw new FileSystemException($path->getPath() . ' is not a directory'); } if (!$path->isReadable()) { throw new FileSystemException($path->getPath() . ' is not readable'); } $paths = array(); $files = $path->read($recursive); foreach ($files as $file) { $path = $this->getPath($file, false); $paths[$path->getPath()] = $path; } if ($filters) { $paths = $this->applyFilters($paths, $filters); } return $paths; }
/** * Compresses a file into the archive * @param ZipArchive $archive ZipArchive object of PHP * @param zibo\library\filesystem\File $file The file to compress in the archive * @param zibo\library\filesystem\File $prefix The path for the file in the archive * @return null */ private function compressFile(ZipArchive $archive, File $file, File $prefix = null) { if ($prefix == null) { $prefix = new File($file->getName()); } else { $prefix = new File($prefix, $file->getName()); } $children = null; if ($file->exists()) { if ($file->isDirectory()) { $children = $file->read(); } else { $archive->addFile($file->getPath(), $prefix->getPath()); return; } } if (empty($children)) { $archive->addEmptyDir($prefix->getPath()); } else { foreach ($children as $file) { $this->compressFile($archive, $file, $prefix); } } }
public function testUncompress() { $archive = new Zip($this->file); $archive->compress($this->compressFiles); $archive->compress($this->compressFiles, $this->prefix); $uncompressFiles = array(); foreach ($this->compressFiles as $file) { $uncompressFiles[] = new File($file->getName()); $uncompressFiles[] = new File($this->prefix, $file->getName()); } $uncompressDirectory = new File('/tmp/zibo/'); $archive->uncompress($uncompressDirectory); try { $uncompressedFiles = $uncompressDirectory->read(true); foreach ($uncompressFiles as $file) { $uncompressedFile = new File($uncompressDirectory, $file); $this->assertArrayHasKey($uncompressedFile->getPath(), $uncompressedFiles, $uncompressedFile->getPath()); } } catch (FileSystemException $e) { $this->fail('Uncompress directory was not created'); } $uncompressDirectory->delete(); $this->file->delete(); }
/** * Adds the breadcrumbs for the current path * @param zibo\library\html\Breadcrumbs $breadcrumbs The breadcrumbs container * @param string $action URL to the path action * @param zibo\library\filesystem\File $path The path to add */ private function addBreadcrumbs($breadcrumbs, $action, File $path = null) { if ($path == null) { return; } $pieces = explode(File::DIRECTORY_SEPARATOR, $path->getPath()); $breadcrumbAction = $action; foreach ($pieces as $piece) { if (empty($piece) || $piece == FileBrowser::DEFAULT_PATH) { continue; } $breadcrumbAction .= '/' . $piece; $breadcrumbs->addBreadcrumb($breadcrumbAction, $piece); } }
/** * Get the parent of the provided file * * If you provide a path like /var/www/yoursite, the parent will be /var/www * @param File $file * @return File the parent of the file */ public function getParent(File $file) { $path = $file->getPath(); if (strpos($path, File::DIRECTORY_SEPARATOR) === false) { $parent = new File('.'); return new File($this->getAbsolutePath($parent)); } $name = $file->getName(); $nameLength = strlen($name); $parent = substr($path, 0, ($nameLength + 1) * -1); if (!$parent) { return new File(File::DIRECTORY_SEPARATOR); } return new File($parent); }
/** * Constructs a new form * @param string $action URL where this form will point to * @param string $name Name of the form * @param string $translationSubmit Translation key for the submit button * @param zibo\library\filesystem\File $path Path of the file or directory * @return null */ public function __construct($action, $name, $translationSubmit, File $path = null) { parent::__construct($action, $name, $translationSubmit); $pathValue = '.'; if ($path != null) { $pathValue = $path->getPath(); } $fieldFactory = FieldFactory::getInstance(); $requiredValidator = new RequiredValidator(); $pathField = $fieldFactory->createField(FieldFactory::TYPE_HIDDEN, self::FIELD_PATH, $pathValue); $pathField->addValidator($requiredValidator); $nameField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_NAME); $nameField->addValidator($requiredValidator); $this->addField($pathField); $this->addField($nameField); }
protected function setUp() { $path = new File(__DIR__ . '/../../../../'); $this->setUpApplication($path->getPath()); try { $browser = new GenericBrowser(new File(getcwd())); $configIO = new IniConfigIO(Environment::getInstance(), $browser); Zibo::getInstance($browser, $configIO); } catch (ZiboException $e) { } $this->server = new Server(); $this->service = new SumService(); $this->serviceName = 'test.sum'; $this->callback = array($this->service, 'sum'); $this->resultType = 'int'; $this->parameterTypes = array('int', 'int'); }
/** * Look for files by looping through the include paths * @param string $fileName relative path of a file in the Zibo filesystem structure * @param boolean $firstOnly true to get the first matched file, false to get an array * with all the matched files * @return zibo\library\filesystem\File|array Depending on the firstOnly flag, an instance or an array of zibo\library\filesystem\File * @throws zibo\ZiboException when fileName is empty or not a string */ protected function lookupFile($fileName, $firstOnly) { if (!$fileName instanceof File && !String::isString($fileName, String::NOT_EMPTY)) { throw new FileSystemException('Provided filename is empty'); } $files = array(); $includePaths = $this->getIncludePaths(); foreach ($includePaths as $includePath) { $file = new File($includePath, $fileName); if (!$file->exists()) { continue; } if ($firstOnly) { return $file; } $files[$file->getPath()] = $file; } if ($firstOnly) { return null; } ksort($files); return $files; }
/** * Unlocks the provided file * @param File $file File to unlock * @return null * @throws zibo\library\filesystem\exception\FileSystemException when the file is not locked */ public function unlock(File $file) { $lockFile = $file->getLockFile(); if (!$this->exists($lockFile)) { throw new FileSystemException('Could not unlock ' . $file->getPath() . ': The file is not locked'); } $this->delete($lockFile); }
*/ $cacheDirectory = new File($baseDirectory, $cachePath); $cacheDirectory->create(); /** * The base URL of the Zibo installation * @var string */ $baseUrl = $zibo->getRequest()->getBaseUrl(); /* * Define the configuration constants of TCPDF */ define('K_TCPDF_EXTERNAL_CONFIG', true); define('K_PATH_MAIN', $vendorDirectory); define('K_PATH_URL', $baseUrl); define('K_PATH_FONTS', K_PATH_MAIN . 'fonts/'); define('K_PATH_CACHE', $cacheDirectory->getPath() . '/'); define('K_PATH_URL_CACHE', $baseUrl . '/' . $cachePath . '/'); define('K_PATH_IMAGES', K_PATH_MAIN . 'images/'); define('K_BLANK_IMAGE', K_PATH_IMAGES . '_blank.png'); define('PDF_PAGE_FORMAT', 'A4'); define('PDF_PAGE_ORIENTATION', 'P'); define('PDF_CREATOR', 'TCPDF'); define('PDF_AUTHOR', 'TCPDF'); define('PDF_HEADER_TITLE', 'TCPDF Example'); define('PDF_HEADER_STRING', "by Nicola Asuni - Tecnick.com\nwww.tcpdf.org"); define('PDF_HEADER_LOGO', 'tcpdf_logo.jpg'); define('PDF_HEADER_LOGO_WIDTH', 30); define('PDF_UNIT', 'mm'); define('PDF_MARGIN_HEADER', 5); define('PDF_MARGIN_FOOTER', 10); define('PDF_MARGIN_TOP', 27);
/** * Gets the value of an attribute from the provided XML element * @param zibo\library\filesystem\File $file the file which is being read * @param DomElement $element the element from which the attribute needs to be retrieved * @param string $name name of the attribute * @param boolean $required flag to see if the value is required or not * @return string * @throws zibo\ZiboException when the attribute is required but not set or empty */ private function getAttribute(File $file, DOMElement $element, $name, $required = true) { $value = $element->getAttribute($name); if ($required && empty($value)) { throw new ZiboException('Attribute ' . $name . ' not set in ' . $file->getPath()); } return $value; }
/** * Write modules to the provided path * @param zibo\library\filesystem\File $path Path to write the modules definitions to * @param array $modules Array with Module instances * @return null */ public function writeModules(File $path, array $modules) { $dom = new Document('1.0', 'utf-8'); $dom->formatOutput = true; $dom->setSchemaFileFromConfig(self::CONFIG_MODULES_SCHEMA); $modulesElement = $dom->createElementNS(self::XML_NAMESPACE, self::TAG_MODULES); $modulesElement->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', self::XML_NAMESPACE . ' ' . self::XML_NAMESPACE . ' '); $dom->appendChild($modulesElement); foreach ($modules as $namespace => $names) { foreach ($names as $name => $module) { $moduleElement = $this->getModuleElementFromModule($dom, $module, self::TAG_MODULE); $modulesElement->appendChild($moduleElement); } } $path->create(); $file = new File($path, self::MODULE_FILE); $dom->save($file->getPath()); }
public function testGetPath() { $path = 'test/test.txt'; $file = new File($path); $this->assertEquals($path, $file->getPath(), 'Path is not the set path'); }
/** * Action to process files and directories from the clipboard to the current path * @param string $action The method to invoke (copy or move) * @param array $files Array with the files to copy * @return null */ private function clipboardFileAction($action, array $files = null) { $this->response->setRedirect($this->getReferer()); if ($files == null) { return; } $root = $this->fileBrowser->getRoot(); $baseDestination = new File($root, $this->path); foreach ($files as $file) { $file = new File($file); $path = $file->getPath(); if (!array_key_exists($path, $this->clipboard)) { continue; } $source = new File($root, $file); $destination = new File($baseDestination, $file->getName()); if (!$destination->isWritable()) { $this->addError(self::TRANSLATION_ERROR_WRITABLE, array('path' => $this->fileBrowser->getPath($destination))); continue; } $source->{$action}($destination); unset($this->clipboard[$path]); } }
/** * Read the configuration values for the provided file and add them to the provided values array * @param zibo\library\filesystem\File $file file to read and parse * @param array $values Array with the values which are already read * @return array Values array with the read configuration values added * @throws zibo\ZiboException when the provided file could not be read */ private function readFile(File $file, $values) { $fileContent = $file->read(); $ini = @parse_ini_string($fileContent, true); if ($ini === false) { $fileContent = $this->parser->parseReservedWords($fileContent); $ini = @parse_ini_string($fileContent, true, INI_SCANNER_RAW); if ($ini === false) { $error = error_get_last(); throw new ZiboException('Could not read ' . $file->getPath() . ': ' . $error['message']); } $ini = $this->parser->unparseIniWithReservedWords($ini); } return $this->parser->getValuesFromIni($ini, $values); }
/** * Downloads a file from the FTP server * @param string $remoteFile The source file on the FTP server * @param zibo\library\filesystem\File $localFile The destination to save the source in * @param integer $mode ASCII or binary (constants FTP_ASCII or FTP_BINARY) * @return null * @throws zibo\library\ftp\exception\FtpException when not connected to the FTP server * @throws zibo\library\ftp\exception\FtpException when the file could not be downloaded */ public function get($remoteFile, File $localFile, $mode = null) { $this->checkConnected(); if ($localFile->exists() && $localFile->isDirectory()) { throw new FtpException('Could not download ' . $remoteFile . ': Destination ' . $localFile . ' is a directory'); } elseif (!$localFile->isWritable()) { throw new FtpException('Could not download ' . $remoteFile . ': Destination ' . $localFile . ' is a not writable'); } if (!$mode) { $mode = FTP_BINARY; } if (!@ftp_get($this->handle, $localFile->getPath(), $remoteFile, $mode)) { throw new FtpException('Could not download ' . $remoteFile . ': A problem occured while downloading'); } }
public function testUncompress() { $archive = new Phar($this->file); $archive->compress($this->compressFiles); $archive->compress($this->compressFiles, $this->prefix); $uncompressDirectory = new File('application/data/uncompress'); if ($uncompressDirectory->exists()) { $uncompressDirectory->delete(); } $uncompressFiles = array(); foreach ($this->compressFiles as $file) { $uncompressFiles[] = new File($file->getName()); $uncompressFiles[] = new File($this->prefix, $file->getName()); } try { $archive->uncompress($uncompressDirectory); } catch (FileSystemException $e) { $this->fail('Uncompress directory was not created'); } $contentBuildXml = $this->compressFiles[1]->read(); $uncompressedFiles = $uncompressDirectory->read(true); foreach ($uncompressFiles as $file) { $uncompressedFile = new File($uncompressDirectory, $file); $this->assertArrayHasKey($uncompressedFile->getPath(), $uncompressedFiles, $uncompressedFile->getPath()); if ($file->getName() == 'build.xml' && $uncompressedFile->read() != $contentBuildXml) { $this->fail('Content of the uncompressed build.xml is not the same as the original file'); } } $uncompressDirectory->delete(); }
/** * Get the cache file for the image source * @param zibo\library\filesystem\File $source image source to get a cache file for * @return zibo\library\filesystem\File unique name for a source file, in the cache directory, with the thumbnailer, width and height encoded into */ private function getCacheFile(File $source) { $filename = md5($source->getPath() . '-thumbnailer=' . $this->thumbnailer . '-width=' . $this->thumbnailWidth . '-height=' . $this->thumbnailHeight); $filename .= '.' . $source->getExtension(); return new File(self::CACHE_PATH, $filename); }
/** * Compresses a directory into the archive * @param \Phar $archive Phar object of PHP * @param zibo\library\filesystem\File $dir The directory to compress in the archive * @param zibo\library\filesystem\File $prefix The path for the directory in the archive * @return null */ private function compressDirectory(PhpPhar $archive, File $dir, File $prefix) { $children = $dir->read(); if (empty($children)) { $archive->addEmptyDir(new File($prefix->getPath(), $dir->getName())); } else { foreach ($children as $file) { $this->compressFile($archive, $file, $prefix); } } }