/** * Check if file extension in whitelist. Client name of uploaded file will be used! * * @param mixed $filename * @param array $extensions * @return bool */ public function extension($filename, $extensions) { if (!is_array($extensions)) { $extensions = array_slice(func_get_args(), 1); } if ($filename instanceof UploadedFileInterface) { return in_array($this->files->extension($filename->getClientFilename()), $extensions); } return in_array($this->files->extension($filename), $extensions); }
/** * Detect compiler by view path (automatically resolved based on extension). * * @todo cache needed? * @param string $path * @return string */ protected function detectEngine($path) { if (isset($this->associationCache[$path])) { return $this->associationCache[$path]; } //File extension can help us to detect engine faster (attention, does not work with complex //extensions at this moment). $extension = $this->files->extension($path); $detected = null; foreach ($this->config->getEngines() as $engine) { if (!empty($extension) && $extension == $this->config->engineExtension($engine)) { //Found by extension $detected = $engine; break; } //Trying automatic (no extension) detection $loader = $this->loader($engine); try { if (!empty($loader->viewName($path))) { $detected = $engine; } } catch (LoaderException $exception) { //Does not related to such engine } } if (empty($detected)) { throw new ViewsException("Unable to detect view engine for '{$path}'."); } return $this->associationCache[$path] = $detected; }
/** * Get list of view names associated with their View class. * * @param string $namespace * @return array * @throws ViewException */ public function getViews($namespace) { if (!isset($this->namespaces[$namespace])) { throw new ViewException("Invalid view namespace '{$namespace}'."); } $result = []; foreach ($this->namespaces[$namespace] as $location) { $location = $this->files->normalizePath($location); foreach ($this->files->getFiles($location) as $filename) { $foundEngine = false; foreach ($this->config['engines'] as $engine => $options) { if (in_array($this->files->extension($filename), $options['extensions'])) { $foundEngine = $engine; break; } } if (empty($foundEngine)) { //No engines found = not view continue; } //View filename without extension $filename = substr($filename, 0, -1 - strlen($this->files->extension($filename))); $name = substr($filename, strlen($location) + strlen(FilesInterface::SEPARATOR)); $result[$name] = $this->viewClass($foundEngine, $namespace, $name); } } return $result; }
/** * Load all bundle strings from specified language. * * @param string $language * @param string $prefix Only bundle names started with this prefix will be exported. * @return array */ private function loadBundles($language, $prefix = '') { $bundles = $this->files->getFiles($this->translator->config()['languages'][$language]['directory']); $result = []; foreach ($bundles as $filename) { $bundle = substr(basename($filename), 0, -1 * strlen($this->files->extension($filename))); if (!empty($prefix) && stripos($bundle, $prefix) !== 0) { continue; } try { $result[$bundle] = (include $filename); } catch (\Exception $exception) { } } return $result; }