/** * Touch a state document (make sure that it exists). * @param string $key State document key. * @return bool True if document exists. */ public function touch($key) { if (!isset($this->files[$key])) { if (!Utilities::dirExists($this->dir, true)) { return false; } $this->files[$key] = new PhpStore($this->dir . '/' . $key . '.php'); } return $this->files[$key]->touch(); }
/** * Construct file log handler. * @param string $filePath Log file path. * @param string $level Minimum log level, see {@see \Psr\Log\LogLevel}. * @param bool $useLocking Whether to lock the file before appending to ensure * atomicity of each write. */ public function __construct($filePath, $level = LogLevel::DEBUG, $useLocking = false) { if (!file_exists($filePath)) { $dir = dirname($filePath); if (!Utilities::dirExists($dir)) { trigger_error(tr('Could not create log directory: %1', $dir), E_USER_WARNING); $this->stream = false; return; } if (!touch($filePath)) { trigger_error(tr('Could not create log file: %1', $filePath), E_USER_WARNING); $this->stream = false; return; } } $this->file = realpath($filePath); parent::__construct(null, $level, $useLocking); }
/** * Run build script. * @param string $root Package root. * @throws InstallException on failure. */ public function run($root) { $this->buildPath = $this->p('tmp/build/' . $this->name); if (!Utilities::dirExists($this->buildPath, true, true)) { throw new InstallException('Could not create build directory: ' . $this->buildPath); } $this->installPath = Paths::combinePaths($root, $this->name); if (!Utilities::dirExists($this->installPath, true, true)) { throw new InstallException('Could not create install directory: ' . $this->installPath); } if (isset($this->prepare)) { $this->info(tr('Preparing...')); call_user_func($this->prepare, $this); } $this->fetchSources(); if (isset($this->build)) { $this->info(tr('Building...')); call_user_func($this->build, $this); } if (isset($this->install)) { $this->info(tr('Installing...')); call_user_func($this->install, $this); } $this->manifest['name'] = $this->name; $this->manifest['version'] = $this->version; if (isset($this->manifestFile) and isset($this->manifest)) { $this->info(tr('Creating manifest...')); $manifestFile = $this->installPath . '/' . $this->manifestFile; file_put_contents($manifestFile, Json::prettyPrint($this->manifest)); } }
/** * {@inheritdoc} */ public function before() { $this->view->data->title = tr('I18n'); if (isset($this->m->Extensions)) { $this->viewData['extensions'] = $this->m->Extensions->listAllExtensions(); } else { $this->viewData['extensions'] = null; } if (isset($this->m->Themes)) { $this->viewData['themes'] = $this->m->Themes->listAllThemes(); } else { $this->viewData['themes'] = null; } $this->viewData['dir'] = $this->p('app/languages'); $this->viewData['project'] = $this->app->name . ' ' . $this->app->version; $this->rootDir = $this->p('app'); if (isset($this->request->query['scope'])) { $scope = $this->request->query['scope']; if ($scope === 'lib') { $this->scope = 'lib'; $this->viewData['dir'] = $this->p('Core/languages'); $this->viewData['project'] = 'Jivoo ' . \Jivoo\VERSION; $this->rootDir = \Jivoo\PATH; } else { if (strpos($scope, '-') !== false) { $scope = explode('-', $scope); if (isset($this->m->Extensions) and $scope[0] === 'extension') { if (isset($this->viewData['extensions'][$scope[1]])) { $this->scope = 'extension'; $this->extension = $this->viewData['extensions'][$scope[1]]; $this->viewData['dir'] = $this->extension->p($this->app, 'languages'); $this->viewData['project'] = $this->extension->name . ' ' . $this->extension->version; $this->rootDir = $this->extension->p($this->app, ''); } } else { if (isset($this->m->Themes) and $scope[0] === 'theme') { if (isset($this->viewData['themes'][$scope[1]])) { $this->scope = 'theme'; $this->theme = $this->viewData['themes'][$scope[1]]; $this->viewData['dir'] = $this->theme->p($this->app, 'languages'); $this->viewData['project'] = $this->theme->name . ' ' . $this->theme->version; $this->rootDir = $this->theme->p($this->app, ''); } } } } } } $this->viewData['dirExists'] = Utilities::dirExists($this->viewData['dir']); if ($this->viewData['dirExists']) { $this->viewData['languages'] = $this->findLanguages($this->viewData['dir']); } return parent::before(); }
/** * Compile an HTML template. * @param string $dir Template dir. * @param string $template Absolute path to template. * @return string Absolute path to compiled template. * @throws InvalidTemplateException If template could not be compiled. */ public function compileTemplate($dir, $template) { if (!isset($this->compiled[$template])) { $source = $dir . $template; $compiled = $dir . 'compiled/' . $template . '.php'; $dir = dirname($compiled); if (!Utilities::dirExists($dir)) { throw new InvalidTemplateException(tr('Could not create directory: %1', $dir)); } $output = $this->compiler->compile($source); $file = fopen($compiled, 'w'); if (!$file) { throw new InvalidTemplateException(tr('Could not write compiled template: %1', $compiled)); } $this->logger->info(tr('Compiling template %1', $source)); fwrite($file, $output); fclose($file); $this->compiled[$template] = $compiled; } return $this->compiled[$template]; }