/** * Constructs a new cache IO * @param zibo\library\filesystem\File $path Path for the type cache files * @return null */ public function __construct(File $path = null) { if ($path === null) { $path = new File(self::DEFAULT_PATH); } $this->path->create(); $this->cache = array(); }
/** * Constructs a new cache IO * @param zibo\library\filesystem\File $path Path for the type cache files * @return null */ public function __construct(File $path = null) { if ($path === null) { $path = new File(self::DEFAULT_PATH); } $this->path = new File(Zibo::getInstance()->getRootPath(), $path); $this->path->create(); $this->cache = array(); }
/** * 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 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; }
/** * Constructs a new repository * @param zibo\library\filesystem\File $directory The directory of the repository * @return null * @throws zibo\ZiboException when the provided directory does not exist or when it's not writable */ public function __construct(File $directory) { $directory->create(); if (!$directory->isDirectory()) { throw new ZiboException($directory->getAbsolutePath() . ' is not a directory'); } if (!$directory->isWritable()) { throw new ZiboException($directory->getAbsolutePath() . ' is not writable'); } $this->directory = $directory; $this->isIndexDirty = false; $this->readIndexFile(); }
/** * @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(); }
public function testReadFromCache() { $this->setUpReadCache(); $type = 'cache'; $id = 'testRead'; $expected = 'Test value'; $object = new CacheObject($type, $id, $expected); $cachePath = new File($this->path, $type); $cachePath->create(); $cacheFile = new File($this->path, $type . File::DIRECTORY_SEPARATOR . $id); $cacheFile->write(serialize($object)); $result = $this->cache->readFromCache($type, $id); $this->assertEquals($object, $result); $this->assertEquals($expected, $result->getData()); $this->tearDownCache(); }
/** * Checks if the application directory exists and is writable * @return null */ public function performCheck() { $root = Zibo::getInstance()->getRootPath(); $directory = new File($root, $this->path); $this->isMet = false; if (!$directory->exists()) { try { $directory->create(); } catch (ZiboException $exception) { $this->message = $this->messageExists; return; } } if ($this->messageWritable && !$directory->isWritable()) { $this->message = $this->messageWritable; return; } $this->isMet = true; }
/** * Assign the smarty configuration to the engine * @param zibo\core\Zibo $zibo instance of Zibo to get the configuration from * @return null */ private function parseConfiguration(Zibo $zibo) { $this->smarty->caching = false; $this->smarty->compile_dir = $zibo->getConfigValue(self::CONFIG_COMPILE_DIRECTORY, self::DEFAULT_COMPILE_DIRECTORY); $directory = new File($this->smarty->compile_dir); $directory->create(); $smartyPluginDirectories = $zibo->getConfigValue(self::CONFIG_PLUGINS, array()); if (!is_array($smartyPluginDirectories)) { $smartyPluginDirectories = array($smartyPluginDirectories); } foreach ($smartyPluginDirectories as $directory) { $this->smarty->plugins_dir[] = $directory; } }
/** * The base path of the Zibo installation * @var zibo\library\filesystem\File */ $baseDirectory = $zibo->getRootPath(); /** * The path for the TCPDF cache * @var zibo\library\filesystem\File */ $cachePath = new File(Zibo::DIRECTORY_APPLICATION . '/' . Zibo::DIRECTORY_PUBLIC . '/tcpdf'); /** * The full directory of the TCPDF cache * @var zibo\library\filesystem\File */ $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/');
/** * 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()); }
/** * Uncompresses the archive to the provided destination * @param zibo\library\filesystem\File $destination Destination of the uncompressed files * @return null */ public function uncompress(File $destination) { $path = $this->file->getAbsolutePath(); $zip = new ZipArchive(); if ($zip->open($path) !== true) { throw new ArchiveException('Could not open ' . $path); } $destination->create(); $zip->extractTo($destination->getAbsolutePath()); $zip->close(); }
/** * Gets the user directory for the current user * @return null|zibo\library\filesystem\File The user directory */ public function getUserDirectory() { $user = $this->securityManager->getUser(); if (!$user) { return null; } $id = $user->getUserId(); $directory = new File($this->path, $id); $directory->create(); return $directory; }
/** * Extracts a source to destination * @param zibo\library\filesystem\File $source The source phar or directory * @param zibo\library\filesystem\File $destination The destination directory * @return null */ private function extract(File $source, File $destination) { $destination->create(); $files = $source->read(); if (!$files) { return; } foreach ($files as $sourceFile) { $destinationFile = new File($destination, $sourceFile->getName()); if ($sourceFile->isDirectory()) { $this->extract($sourceFile, $destinationFile); } else { $destinationFile->write($sourceFile->read()); } } }
/** * Initialize the session configuration and start the session * @return null */ private function initialize() { $zibo = Zibo::getInstance(); $sessionTime = $zibo->getConfigValue(self::CONFIG_SESSION_TIME, self::DEFAULT_SESSION_TIME) * 60; $sessionProbability = $zibo->getConfigValue(self::CONFIG_SESSION_GC_PROBABILITY, self::DEFAULT_SESSION_GC_PROBABILITY); $sessionDivisor = $zibo->getConfigValue(self::CONFIG_SESSION_GC_DIVISOR, self::DEFAULT_SESSION_GC_DIVISOR); $sessionPath = $zibo->getConfigValue(self::CONFIG_SESSION_PATH, self::DEFAULT_SESSION_PATH); $fileSessionPath = new File($sessionPath); $fileSessionPath->create(); ini_set('session.gc_maxlifetime', $sessionTime); ini_set('session.gc_probability', $sessionProbability); ini_set('session.gc_divisor', $sessionDivisor); ini_set('session.save_path', $sessionPath); $this->startSession(); if (!array_key_exists(self::SESSION_NAME, $_SESSION)) { $_SESSION[self::SESSION_NAME] = array(); } }
/** * Installs the provided module on the filesystem * @param string $moduleFileContent Decoded Base64 of the contents of the module phar file * @param string $namespace The namespace of the module * @param string $name The name of the module * @return null * @throws Exception when an error occured */ private function installModuleLocally($moduleFileContent, $namespace, $name) { if ($moduleFileContent === '') { throw new ZiboException('No sources for the module ' . $namespace . '.' . $name . ' recieved from the repository'); } $downloadDirectory = new File('application/data'); $downloadDirectory->create(); $moduleFile = new File($downloadDirectory, $namespace . '.' . $name . '.phar'); $moduleFile->write($moduleFileContent); $exception = null; try { $this->installer->installModule($moduleFile); } catch (Exception $e) { $exception = $e; } if ($moduleFile->exists()) { $moduleFile->delete(); } if ($exception) { throw $exception; } }