Example #1
0
 /**
  * Apply
  *
  * @throws Exception
  * @return bool
  */
 protected function _register()
 {
     // let's use some speaking variable names... :)
     $variableName = $this->param1;
     $value = $this->value;
     Est_VariableStorage::add($variableName, $value);
     $this->addMessage(new Est_Message(sprintf('Storing value "%s" for variable "%s".', $value, $variableName), Est_Message::OK));
 }
 /**
  * Get value from row
  *
  * @param array $row
  * @param string $environment
  * @param string $fallbackEnvironment
  * @param Est_Handler_Abstract $handler
  * @return string
  */
 private function getValueFromRow(array $row, $environment, $fallbackEnvironment, Est_Handler_Abstract $handler = null)
 {
     $value = null;
     $defaultColumnIndex = $this->getColumnIndexForEnvironment($fallbackEnvironment, true);
     $envColumnIndex = $this->getColumnIndexForEnvironment($environment);
     if (array_key_exists($envColumnIndex, $row)) {
         $value = $row[$envColumnIndex];
         if ($value == '--empty--') {
             $value = '';
         } elseif (preg_match('/###REF:([^#]*)###/', $value, $matches)) {
             $value = $this->getValueFromRow($row, $matches[1], $fallbackEnvironment);
         } elseif ($value == '') {
             if ($defaultColumnIndex !== FALSE) {
                 $value = $row[$defaultColumnIndex];
             }
         }
     } else {
         if ($defaultColumnIndex !== FALSE && array_key_exists($defaultColumnIndex, $row)) {
             $value = $row[$defaultColumnIndex];
         }
     }
     if (!is_null($handler)) {
         $value = str_replace('###PARAM1###', $handler->getParam1(), $value);
         $value = str_replace('###PARAM2###', $handler->getParam2(), $value);
         $value = str_replace('###PARAM3###', $handler->getParam3(), $value);
     }
     while (preg_match('/###VAR:([^#]*)###/', $value, $matches)) {
         $var = Est_VariableStorage::get($matches[1]);
         if ($var === false) {
             throw new \Exception('Variable "' . $matches[1] . '" is not set');
         }
         $value = preg_replace('/###VAR:([^#]*)###/', $var, $value, 1);
     }
     while (preg_match('/###FILE:([^#]*)###/', $value, $matches)) {
         $fileName = $matches[1];
         if (!file_exists($fileName)) {
             throw new \Exception('File "' . $fileName . '" does not exist');
         }
         $content = trim(file_get_contents($fileName));
         $value = preg_replace('/###FILE:([^#]*)###/', $content, $value, 1);
     }
     $value = str_replace('###ENVIRONMENT###', $environment, $value);
     $value = str_replace('###CWD###', getcwd(), $value);
     return $this->replaceWithEnvironmentVariables($value);
 }