PKPLocale::requireComponents PHP Method

requireComponents() static public method

.. constant. An optional final parameter may be supplied to specify the locale (e.g. 'en_US').
static public requireComponents ( )
    static function requireComponents()
    {
        $params = func_get_args();
        $paramCount = count($params);
        if ($paramCount === 0) {
            return;
        }
        // Get the locale
        $lastParam = $params[$paramCount - 1];
        if (is_string($lastParam)) {
            $locale = $lastParam;
            $paramCount--;
        } else {
            $locale = AppLocale::getLocale();
        }
        // Backwards compatibility: the list used to be supplied
        // as an array in the first parameter.
        if (is_array($params[0])) {
            $params = $params[0];
            $paramCount = count($params);
        }
        // Go through and make sure each component is loaded if valid.
        $loadedComponents =& Registry::get('loadedLocaleComponents', true, array());
        $filenameComponentMap = AppLocale::getFilenameComponentMap($locale);
        for ($i = 0; $i < $paramCount; $i++) {
            $component = $params[$i];
            // Don't load components twice
            if (isset($loadedComponents[$locale][$component])) {
                continue;
            }
            // Validate component
            if (!isset($filenameComponentMap[$component])) {
                fatalError('Unknown locale component ' . $component);
            }
            $filename = $filenameComponentMap[$component];
            AppLocale::registerLocaleFile($locale, $filename);
            $loadedComponents[$locale][$component] = true;
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Execute gzip to compress or extract files.
  * @param $filePath string file to be compressed or uncompressed.
  * @param $decompress boolean optional Set true if the passed file
  * needs to be decompressed.
  * @param $errorMsg string
  * @return false|string The file path that was created with the operation
  * or false in case of fail.
  */
 private function _executeGzip($filePath, $decompress = false, &$errorMsg)
 {
     PKPLocale::requireComponents(LOCALE_COMPONENT_PKP_ADMIN);
     $gzipPath = Config::getVar('cli', 'gzip');
     if (!is_executable($gzipPath)) {
         $errorMsg = __('admin.error.executingUtil', array('utilPath' => $gzipPath, 'utilVar' => 'gzip'));
         return false;
     }
     $gzipCmd = escapeshellarg($gzipPath);
     if ($decompress) {
         $gzipCmd .= ' -d';
     }
     // Make sure any output message will mention the file path.
     $output = array($filePath);
     $returnValue = 0;
     $gzipCmd .= ' ' . $filePath;
     if (!Core::isWindows()) {
         // Get the output, redirecting stderr to stdout.
         $gzipCmd .= ' 2>&1';
     }
     exec($gzipCmd, $output, $returnValue);
     if ($returnValue > 0) {
         $errorMsg = __('admin.error.utilExecutionProblem', array('utilPath' => $gzipPath, 'output' => implode(PHP_EOL, $output)));
         return false;
     }
     if ($decompress) {
         return substr($filePath, 0, -3);
     } else {
         return $filePath . '.gz';
     }
 }