/**
  * 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;
 }
 public function providerGetFiles()
 {
     $systemPath = realpath(dirname(__FILE__) . '/../../../../../../');
     $file = 'test/src/zibo/library/filesystem/browser/GenericBrowserTest.php';
     $resultFile = new File($systemPath, $file);
     return array(array(array(), 'unexistantFile'), array(array($resultFile->getAbsolutePath() => $resultFile), $file));
 }
 public function providerGetFiles()
 {
     $systemPath = realpath(__DIR__ . '/../../../../../');
     $file = 'src/zibo/core/filesystem/GenericFileBrowser.php';
     $resultFile = new File($systemPath, $file);
     return array(array(array(), 'unexistantFile'), array(array($resultFile->getAbsolutePath() => $resultFile), $file));
 }
Example #4
0
 /**
  * Constructs a new file view
  * @param zibo\library\filesystem\File $file File to render
  * @return null
  */
 public function __construct(File $file)
 {
     if (!$file->exists() || $file->isDirectory()) {
         throw new ZiboException($file . ' does not exists or is a directory.');
     }
     $this->file = $file;
 }
Example #5
0
 /**
  * Renders the file view
  * @param boolean $return True to return the contents of the file, false
  * to passthru the file to the output
  * @return null|string
  */
 public function render($return = true)
 {
     if ($return) {
         return $this->file->read();
     }
     $this->file->passthru();
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * Checks if the provided file is allowed by this filter
  * @param zibo\library\filesystem\File $file File to check
  * @return boolean True if the file is allowed, false otherwise
  */
 public function isAllowed(File $file)
 {
     $result = !$this->include;
     if ($file->isDirectory()) {
         $result = !$result;
     }
     return $result;
 }
 /**
  * Checks if the provided file is allowed by this filter
  * @param zibo\library\filesystem\File $file File to check
  * @return boolean True if the file is allowed, false otherwise
  */
 public function isAllowed(File $file)
 {
     $result = !$this->include;
     $extension = $file->getExtension();
     if (in_array($extension, $this->extensions)) {
         $result = !$result;
     }
     return $result;
 }
Example #11
0
 /**
  * Gets the temporary directory for the installation process
  * @param string $path The path in the temporary directory
  * @return zibo\library\filesystem\File
  */
 public static function getTempDirectory($path = null)
 {
     $rootDirectory = Zibo::getInstance()->getRootPath();
     $rootDirectory = $rootDirectory->getPath();
     $path = 'zibo-' . substr(md5($rootDirectory), 0, 7) . ($path ? '/' . $path : '');
     $temp = new File(sys_get_temp_dir(), $path);
     $temp->create();
     return $temp;
 }
 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);
 }
Example #13
0
 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');
 }
 /**
  * Creates an archive object for the provided file
  * @param zibo\library\filesystem\File $file File of the archive
  * @return Archive
  * @throws zibo\library\archive\exception\ArchiveException when the provided file is not a supported archive, based on extension
  */
 public function getArchive(File $file)
 {
     $extension = $file->getExtension();
     if (!isset($this->types[$extension])) {
         throw new ArchiveException('Unsupported archive: ' . $extension);
     }
     $className = $this->types[$extension];
     $reflection = new ReflectionClass($className);
     $archive = $reflection->newInstance($file);
     return $archive;
 }
Example #15
0
 /**
  * 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());
 }
Example #16
0
 /**
  * Get the mime type of a file based on it's extension
  * @param File $file
  * @return string the mime type of the file
  */
 public static function getMimeType(File $file)
 {
     $extension = $file->getExtension();
     if (empty($extension)) {
         return self::MIME_UNKNOWN;
     }
     $mime = Zibo::getInstance()->getConfigValue(self::CONFIG_MIME . $extension);
     if (!$mime) {
         $mime = self::MIME_UNKNOWN;
     }
     return $mime;
 }
Example #17
0
 /**
  * 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());
         }
     }
 }
 /**
  * Finished the installation, remove the installation module and redirect
  * @return null
  */
 public function finish()
 {
     $installModule = new File(__DIR__ . '/../../../../');
     $installModule->delete();
     $installScript = new File($installModule->getParent()->getParent(), 'install.php');
     if ($installScript->exists() && $installScript->isWritable()) {
         $installScript->delete();
     }
     $zibo = Zibo::getInstance();
     $request = $zibo->getRequest();
     $response = $zibo->getResponse();
     $response->setRedirect($request->getBaseUrl());
 }
Example #19
0
 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());
 }
 /**
  * @dataProvider providerImport
  */
 public function testImport(array $sqls, $content)
 {
     $parent = new File('application/data');
     $parent->create();
     $file = new File($parent, 'tmp.sql');
     $file->write($content);
     $driver = new DriverMock(new Dsn('protocol://host/database'));
     $driver->connect();
     $driver->import($file);
     array_unshift($sqls, 'BEGIN');
     $sqls[] = 'COMMIT';
     $this->assertEquals($sqls, $driver->getSqls());
     $file->delete();
 }
Example #22
0
 /**
  * Connects this connection
  * @return null
  * @throws zibo\library\database\mysql\exception\MysqlException when no connection could be made with the host
  * @throws zibo\library\database\mysql\exception\MysqlException when the database could not be selected
  */
 public function connect()
 {
     $file = new File($this->dsn->getPath());
     if (!$file->exists()) {
         $parent = $file->getParent();
         $parent->create();
     }
     try {
         $this->connection = new SQLite3($file->getAbsolutePath());
     } catch (Exception $exception) {
         $this->connection = null;
         throw new SqliteException($exception->getMessage(), 0, $exception);
     }
 }
 /**
  * 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);
 }
 public function testSetTranslationWhenTranslationFileExists()
 {
     $localeCode = 'locale';
     $key = 'translation5';
     $translation = 'Translation 5';
     $this->io->setTranslation($localeCode, $key, $translation);
     $fileName = Zibo::DIRECTORY_APPLICATION . File::DIRECTORY_SEPARATOR . Zibo::DIRECTORY_L10N . File::DIRECTORY_SEPARATOR . $localeCode . IniTranslationIO::EXTENSION;
     $translationFile = new File($fileName);
     $this->assertTrue($translationFile->exists(), 'No file is being written');
     $iniContent = $translationFile->read();
     $translations = parse_ini_string($iniContent, false);
     $this->assertEquals(5, count($translations));
     $this->assertTrue(array_key_exists($key, $translations));
     $this->assertEquals($translation, $translations[$key]);
 }
Example #25
0
 /**
  * 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);
     }
 }
Example #26
0
 /**
  * Upload a file
  * @param array $file Array with file upload details from PHP
  * @return string path to the uploaded file
  */
 private function uploadFile($file)
 {
     if ($file['error'] == UPLOAD_ERR_NO_FILE) {
         $default = $this->getDefaultValue();
         if (empty($default)) {
             $default = parent::getRequestValue($this->getName() . self::SUFFIX_DEFAULT);
             if (empty($default)) {
                 $default = self::DEFAULT_VALUE;
             }
         }
         return $default;
     }
     $this->isUploadError($file);
     $this->uploadPath->create();
     $uploadFileName = String::safeString($file['name']);
     $uploadFile = new File($this->uploadPath, $uploadFileName);
     if (!$this->willOverwrite()) {
         $uploadFile = $uploadFile->getCopyFile();
     }
     if (!move_uploaded_file($file['tmp_name'], $uploadFile->getPath())) {
         throw new ZiboException('Could not move the uploaded file ' . $file['tmp_name'] . ' to ' . $uploadFile->getPath());
     }
     $uploadFile->setPermissions(0644);
     return $uploadFile->getPath();
 }
 /**
  * Gets the dependency container
  * @param zibo\core\Zibo $zibo Instance of zibo
  * @return zibo\core\di\DependencyContainer
  */
 public function getContainer(Zibo $zibo)
 {
     $file = new File(self::FILE);
     if ($file->exists()) {
         require $file;
     }
     if (isset($container)) {
         return $container;
     }
     $container = $this->io->getContainer($zibo);
     $parent = $file->getParent();
     $parent->create();
     $php = $this->generatePhp($container, $file);
     $file->write($php);
     return $container;
 }
 /**
  * Decorates the cell with the path of the file
  * @param zibo\library\html\table\Cell $cell Cell to decorate
  * @param zibo\library\html\table\Row $row Row of the cell to decorate
  * @param integer $rowNumber Number of the current row
  * @param array $remainingValues Array containing the values of the remaining rows of the table
  * @return null
  */
 public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues)
 {
     $file = $cell->getValue();
     $absoluteFile = new File($this->root, $file);
     if (!$absoluteFile->exists()) {
         $cell->setValue('---');
         return;
     }
     if ($absoluteFile->isDirectory()) {
         $class = self::CLASS_DIRECTORY;
     } else {
         $class = self::CLASS_FILE;
     }
     $html = $this->getNameHtml($file->getPath(), $class);
     $cell->setValue($html);
 }
 /**
  * Gets all available locales
  * @return array all Locale objects
  */
 public function getLocales()
 {
     $file = new File(self::FILE);
     if ($file->exists()) {
         require $file;
     }
     if (isset($locales)) {
         return $locales;
     }
     $locales = $this->io->getLocales();
     $parent = $file->getParent();
     $parent->create();
     $php = $this->generatePhp($locales);
     $file->write($php);
     return $locales;
 }
Example #30
0
 /**
  * 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);
 }