/** * Add callback to filter files * * @param array $callback Callback to register * * @return void */ public function registerCallback(array $callback) { if (!is_callable($callback)) { \Includes\ErrorHandler::fireError('Filtering callback is not valid'); } $this->callbacks[] = $callback; }
/** * Constructor * * @param boolean $nonEmpty Non-empty flag OPTIONAL * @param string $regExp Regular expression OPTIONAL * * @return void */ public function __construct($nonEmpty = false, $regExp = null, $class = '', $id = null) { parent::__construct($nonEmpty, $this->getCleanURLPattern()); if (empty($class)) { \Includes\ErrorHandler::fireError(static::t('Empty "class" parameter is passed to the {{method}}', array('method' => __METHOD__))); } else { $this->class = $class; $this->id = $id; } }
/** * Constructor * * @param string $url Drupal URL * @param string $controller Controller class name * @param string $title Portal title OPTIONAL * @param integer $type Node type OPTIONAL * * @return void */ public function __construct($url, $controller, $title = '', $type = null) { // Check if we can replace second argument to the "\XLite\Controller\Customer\ACustomer" if (!is_subclass_of($controller, '\\XLite\\Controller\\AController')) { \Includes\ErrorHandler::fireError('Portal class is not a controller one'); } $this->url = $url; $this->controller = $controller; $this->title = $title; $this->type = isset($type) ? $type : $this->getDefaultType(); }
/** * Return list of registered plugins * * @param string $hook Hook name OPTIONAL * * @return array */ protected static function getPlugins($hook = null) { if (!isset(static::$plugins)) { // Check config file if (\Includes\Utils\FileManager::isFileReadable(static::getConfigFile())) { // Iterate over all sections foreach (parse_ini_file(static::getConfigFile(), true) as $section => $plugins) { // Set plugins order asort($plugins, SORT_NUMERIC); // Save plugins list static::$plugins[$section] = array_fill_keys(array_keys($plugins), null); } } else { \Includes\ErrorHandler::fireError('Unable to read config file for the Decorator plugins'); } } return \Includes\Utils\ArrayManager::getIndex(static::$plugins, $hook); }
/** * Constructor * * @param string $majorVersion Core major version * @param string $minorVersion Core minor version * @param integer $revisionDate Core revison date * @param integer $size Pack size * * @return void */ public function __construct($majorVersion, $minorVersion, $revisionDate, $size) { if (!$this->checkMajorVersion($majorVersion) || !$this->checkMinorVersion($majorVersion, $minorVersion)) { $version = \Includes\Utils\Converter::composeVersion($majorVersion, $minorVersion); \Includes\ErrorHandler::fireError('Unallowed core version for upgrade: ' . $version); } if ($revisionDate >= \XLite\Core\Converter::time()) { \Includes\ErrorHandler::fireError('Invalid core revision date: "' . date(DATE_RFC822, $revisionDate) . '"'); } $this->majorVersion = $majorVersion; $this->minorVersion = $minorVersion; $this->revisionDate = $revisionDate; $this->size = $size; parent::__construct(); }
/** * Overloaded constructor * * @param string $path Path to the module package * * @return void */ public function __construct($path) { if (!\Includes\Utils\FileManager::isFileReadable($path)) { \Includes\ErrorHandler::fireError('Unable to read module package: "' . $path . '"'); } $this->setRepositoryPath($path); $module = new \PharData($this->getRepositoryPath()); $this->metadata = $module->getMetaData(); if (empty($this->metadata)) { \Includes\ErrorHandler::fireError('Unable to read module metadata: "' . $path . '"'); } parent::__construct(); }
/** * Fire the error them unable to set directory permissions * * @param string $dir Path to check * * @return void */ protected static function fireDirPermissionsError($dir) { \Includes\ErrorHandler::fireError(static::getDirPermissionsErrorMessage($dir)); }
/** * Insert single entity * * @param \XLite\Model\Category|array $entity Data to insert OPTIONAL * * @return \XLite\Model\Category */ protected function performInsert($entity = null) { /** @var \XLite\Model\Category $entity */ $entity = parent::performInsert($entity); $parentID = $entity->getParentId(); if (empty($parentID)) { // Insert root category $this->prepareNewCategoryData($entity); } else { // Get parent for non-root category $parent = $this->getCategory($parentID); if ($parent) { // Reload parent category from database to get correct value of indexes // after batch update in previous call of performInsert on import \XLite\Core\Database::getEM()->refresh($parent); // Update indexes in the nested set $this->defineUpdateIndexQuery('lpos', $parent->getLpos())->execute(); $this->defineUpdateIndexQuery('rpos', $parent->getLpos())->execute(); // Create record in DB $this->prepareNewCategoryData($entity, $parent); } else { \Includes\ErrorHandler::fireError(__METHOD__ . ': category #' . $parentID . ' not found'); } } // Update quick flags if (isset($parent) && null == $entity->getCategoryId()) { $this->updateQuickFlags($parent, $this->prepareQuickFlags(1, $entity->getEnabled() ? 1 : -1)); } return $entity; }
/** * Method to fire an error * * @param string $code Error code (or message) * @param \Includes\DataStructure\Graph $node Node Node caused the error OPTIONAL * * @return void */ public function handleError($code, \Includes\DataStructure\Graph $node = null) { \Includes\ErrorHandler::fireError($this->prepareErrorMessage($code, $node)); }
/** * Insert single entity * * @param \XLite\Model\AEntity|array $entity Data to insert OPTIONAL * * @return void */ protected function performInsert($entity = null) { $entity = parent::performInsert($entity); $parentID = $entity->getParentId(); if (empty($parentID)) { // Insert root category $this->prepareNewCategoryData($entity); } else { // Get parent for non-root category $parent = $this->getCategory($parentID); if ($parent) { // Update indexes in the nested set $this->defineUpdateIndexQuery('lpos', $parent->getLpos())->execute(); $this->defineUpdateIndexQuery('rpos', $parent->getLpos())->execute(); // Create record in DB $this->prepareNewCategoryData($entity, $parent); } else { \Includes\ErrorHandler::fireError(__METHOD__ . ': category #' . $parentID . ' not found'); } } // Update quick flags if (isset($parent)) { $this->updateQuickFlags($parent, $this->prepareQuickFlags(1, $entity->getEnabled() ? 1 : -1)); } return $entity; }
/** * Perform some actions to prohibit access to storefornt * * @return void */ protected function closeStorefront() { \Includes\ErrorHandler::fireError('Storefront is closed', \Includes\ErrorHandler::ERROR_CLOSED); }
/** * Download pack * * @param \XLite\Core\Pack\APack $pack Files to pack * @param boolean $compress Flag OPTIONAL * * @return void */ protected static function download(\XLite\Core\Pack\APack $pack, $compress = true) { if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) { \Includes\Utils\FileManager::mkdir(LC_DIR_TMP); } if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) { \Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable'); } $path = LC_DIR_TMP . $pack->getName() . '.tar'; $phar = static::pack($path, $pack->getDirectoryIterator(), $pack->getMetadata(), $compress); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Content-Length: ' . filesize($path)); echo \Includes\Utils\FileManager::read($path); \Includes\Utils\FileManager::deleteFile($path); exit(0); }
/** * Set data * * @param array $data Data * @param mixed $key Key OPTIONAL * * @return void */ protected static function setData(array $data, $key = true) { $path = static::getFilename($key); $key = static::constructDataKey($key); static::$data[$key] = $data; if (false === @file_put_contents($path, serialize(static::$data[$key]))) { \Includes\ErrorHandler::fireError('Unable write to "' . $path . '" file. Please correct the permissions'); } }
/** * Constructor * * @param \XLite\Model\Module $moduleInstalled Module model object * @param \XLite\Model\Module $moduleForUpgrade Module model object * * @return void */ public function __construct(\XLite\Model\Module $moduleInstalled, \XLite\Model\Module $moduleForUpgrade) { $this->moduleInfoInstalled = $this->getPreparedModuleInfo($moduleInstalled, false); $this->moduleInfoForUpgrade = $this->getPreparedModuleInfo($moduleForUpgrade, true); if (is_null($this->getModuleInstalled())) { \Includes\ErrorHandler::fireError('Module ["' . implode('", "', $this->moduleInfoInstalled) . '"] is not found in DB'); } if (is_null($this->getModuleForUpgrade())) { \Includes\ErrorHandler::fireError('Module ["' . implode('", "', $this->moduleInfoForUpgrade) . '"] is not found in DB' . ' or is not a marketplace module'); } parent::__construct(); }
/** * Constructor * * @param string $dir Directory to iterate over * @param string $pattern Pattern to filter files * @param int $mode Filtering mode OPTIONAL * * @return void */ public function __construct($dir, $pattern = null, $mode = \RecursiveIteratorIterator::LEAVES_ONLY) { $canonicalDir = \Includes\Utils\FileManager::getCanonicalDir($dir); if (empty($canonicalDir)) { \Includes\ErrorHandler::fireError('Path "' . $dir . '" is not exists or is not readable.'); } $this->dir = $canonicalDir; $this->pattern = $pattern; $this->mode = $mode; }
/** * Write data from request into a file * * @param \PEAR2\HTTP\Request\Response $response Response to get data * * @return string */ protected function writeDataToFile(\PEAR2\HTTP\Request\Response $response) { if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) { \Includes\Utils\FileManager::mkdir(LC_DIR_TMP); } if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) { \Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable'); } $path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, uniqid() . '.' . \Includes\Utils\PHARManager::getExtension() ?: 'tar'); return isset($response->body) && \Includes\Utils\FileManager::write($path, $response->body) ? $path : null; }
/** * Method to fire an error * * @param string $code Error code (or message) * @param self $node Node Node caused the error OPTIONAL * * @return void */ public function handleError($code, self $node = null) { \Includes\ErrorHandler::fireError($this->prepareErrorMessage($code, $node)); }