/**
  * Instance.
  *
  * @return InternationalizationComponent
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * @param null|array $alternateConfigValues an alternative set of values to test,
  *                                     usually testing a possible configuration set to be saved.
  *                                     performs validation on current config setup.
  * @return array
  * @throws Zend_Exception
  */
 public function testconfig($alternateConfigValues = null)
 {
     // default to correct config
     $total_config_correct = 1;
     $configStatus = array();
     if ($alternateConfigValues) {
         $configToTest = $alternateConfigValues;
     } else {
         $configToTest = $this->componentConfig;
     }
     Zend_Loader::loadClass('InternationalizationComponent', BASE_PATH . '/core/controllers/components');
     // Process web server user information
     // TODO what should be done if there are warnings??
     $processUser = posix_getpwuid(posix_geteuid());
     $processUserUid = $processUser['uid'];
     $processGroup = posix_getgrgid(posix_geteuid());
     $phpProcessString = InternationalizationComponent::translate(MIDAS_BATCHMAKE_PHP_PROCESS_STRING);
     $phpProcessUserString = $phpProcessString . ' ' . InternationalizationComponent::translate(MIDAS_BATCHMAKE_PHP_PROCESS_USER_STRING);
     $phpProcessNameString = InternationalizationComponent::translate(MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING);
     $phpProcessGroupString = InternationalizationComponent::translate(MIDAS_BATCHMAKE_PHP_PROCESS_GROUP_STRING);
     $phpProcessHomeString = InternationalizationComponent::translate(MIDAS_BATCHMAKE_PHP_PROCESS_HOME_STRING);
     $phpProcessShellString = InternationalizationComponent::translate(MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING);
     $unknownString = InternationalizationComponent::translate(MIDAS_BATCHMAKE_UNKNOWN_STRING);
     $phpProcessUserNameString = $phpProcessUserString . '[' . $phpProcessNameString . ']';
     $phpProcessUserGroupString = $phpProcessUserString . '[' . $phpProcessGroupString . ']';
     $phpProcessUserHomeString = $phpProcessUserString . '[' . $phpProcessHomeString . ']';
     $phpProcessUserShellString = $phpProcessUserString . '[' . $phpProcessShellString . ']';
     $processProperties = array($phpProcessUserNameString => !empty($processUser[MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING]) ? $processUser[MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING] : '', $phpProcessUserGroupString => !empty($processGroup[MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING]) ? $processGroup[MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING] : '', $phpProcessUserHomeString => !empty($processUser[MIDAS_BATCHMAKE_DIR_KEY]) ? $processUser[MIDAS_BATCHMAKE_DIR_KEY] : '', $phpProcessUserShellString => !empty($processUser[MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING]) ? $processUser[MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING] : '');
     foreach ($processProperties as $property => $value) {
         $status = !empty($value);
         $configStatus[] = array(MIDAS_BATCHMAKE_PROPERTY_KEY => $property, MIDAS_BATCHMAKE_STATUS_KEY => $status ? $value : $unknownString, MIDAS_BATCHMAKE_TYPE_KEY => $status ? MIDAS_BATCHMAKE_STATUS_TYPE_INFO : MIDAS_BATCHMAKE_STATUS_TYPE_WARNING);
     }
     foreach (self::$configPropertiesRequirements as $configProperty => $configPropertyRequirement) {
         $configPropertyVal = $configToTest[$configProperty];
         if ($configPropertyVal) {
             // if the property exists, check its configuration
             list($result, $status) = $this->checkFileFlag($configPropertyVal, $processUserUid, $configPropertyRequirement);
             $configStatus[] = array(MIDAS_BATCHMAKE_PROPERTY_KEY => $configProperty, MIDAS_BATCHMAKE_STATUS_KEY => $status, MIDAS_BATCHMAKE_TYPE_KEY => $result ? MIDAS_BATCHMAKE_STATUS_TYPE_INFO : MIDAS_BATCHMAKE_STATUS_TYPE_ERROR);
             // the property is in error, therefore so is the global config
             if (!$result) {
                 $total_config_correct = 0;
             }
         } else {
             // property doesn't exist, both the property and global config are in error
             $configStatus[] = array(MIDAS_BATCHMAKE_PROPERTY_KEY => $configProperty, MIDAS_BATCHMAKE_STATUS_KEY => MIDAS_BATCHMAKE_CONFIG_VALUE_MISSING, MIDAS_BATCHMAKE_TYPE_KEY => MIDAS_BATCHMAKE_STATUS_TYPE_ERROR);
             $total_config_correct = 0;
         }
     }
     // for now assuming will run via condor, so require all of the condor setup
     foreach (self::$applicationsPaths as $app => $pathProperty) {
         $appPath = $configToTest[$pathProperty] . '/' . KWUtils::formatAppName($app);
         list($result, $status) = $this->checkFileFlag($appPath, MIDAS_BATCHMAKE_CHECK_IF_EXECUTABLE);
         $applicationString = InternationalizationComponent::translate(MIDAS_BATCHMAKE_APPLICATION_STRING);
         $configStatus[] = array(MIDAS_BATCHMAKE_PROPERTY_KEY => $applicationString . ' ' . $appPath, MIDAS_BATCHMAKE_STATUS_KEY => $status, MIDAS_BATCHMAKE_TYPE_KEY => $result ? MIDAS_BATCHMAKE_STATUS_TYPE_INFO : MIDAS_BATCHMAKE_STATUS_TYPE_ERROR);
         // the property is in error, therefore so is the global config
         if (!$result) {
             $total_config_correct = 0;
         }
     }
     return array($total_config_correct, $configStatus);
 }
 /**
  * Return the translation of a given string.
  *
  * @param string $text string to translate
  * @return string translated string or the input string if there is no translation
  */
 protected function t($text)
 {
     Zend_Loader::loadClass('InternationalizationComponent', BASE_PATH . '/core/controllers/components');
     return InternationalizationComponent::translate($text);
 }
Example #4
0
 /**
  * Translation view helper.
  *
  * @param string $text text
  * @return string translated text if available, otherwise the input text
  */
 public function t($text)
 {
     Zend_Loader::loadClass('InternationalizationComponent', BASE_PATH . '/core/controllers/components');
     return htmlspecialchars(InternationalizationComponent::translate($text), ENT_QUOTES, 'UTF-8');
 }