public function getVariable($name, $default = null) { if ($name == 'rowsData') { $bodyRowsData = parent::getVariable('rowsData'); if (!$bodyRowsData instanceof \ArrayObject) { throw new \RuntimeException('Variable result must be instance of ' . \ArrayObject::class . '. ' . gettype($bodyRowsData) . ' given'); } $result = []; foreach ($bodyRowsData as $rowData) { if (!$rowData instanceof EntityInterface) { throw new \RuntimeException('Variable result must be instance of ' . EntityInterface::class . '. ' . gettype($rowData) . ' given'); } $row = $rowData->extract(); $result[] = $row; } return $result; } if ($name == 'headRows') { $columnsConf = parent::getVariable('columns'); $result = []; $row = []; foreach ($columnsConf as $columnConf) { $row[] = $columnConf['head']; } $result[] = $row; return $result; } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { if ($name == 'parentCallVar') { return 'parentCallVarValue'; } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { $validCriteria = parent::getVariable('validCriteria'); if (!empty($validCriteria[$name])) { return $validCriteria[$name]; } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { if ($name == 'name') { $myself = $this->fetchMyself(); return $myself['name']; } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { if ($name == 'routeParams') { $id = parent::getVariable('id'); return ['id' => $id]; } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { if ($name != 'options') { return parent::getVariable($name, $default); } $options = [0 => 'All']; foreach ($this->config as $name => $queue) { $options[$name] = $name; } return $options; }
public function getVariable($name, $default = null) { $entity = parent::getVariable('result'); if ($entity) { $data = $entity->extract(); if (isset($data[$name])) { return $data[$name]; } } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { $row = parent::getVariable('row', []); if ($name == 'createdDt' || $name == 'updatedDt') { return date("Y-m-d H:i:s", strtotime($row[$name])); } if (isset($row[$name])) { return $row[$name]; } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { $variable = parent::getVariable($name, $default); if ($name == 'result') { if ($variable !== null) { if (!$variable instanceof EntityInterface) { throw new \RuntimeException('Variable result must be instance of ' . EntityInterface::class . '. ' . gettype($variable) . ' given'); } $variable = $variable->extract(); } } return $variable; }
public function getVariable($name, $default = null) { if ($name == 'country') { if (self::$countries === null) { self::$countries = $this->fetchCountries(self::$countryIds); } $countryId = $this->getVariable('countryId'); if (isset(self::$countries[$countryId]['name'])) { return self::$countries[$countryId]['name']; } } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { if ($name == 'name' || $name == 'countryId') { if (self::$users === null) { self::$users = $this->fetchUsers(self::$userIds); } $userId = $this->getVariable('userId'); if (isset(self::$users[$userId][$name])) { return self::$users[$userId][$name]; } } return parent::getVariable($name, $default); }
public function getVariable($name, $default = null) { $variable = parent::getVariable($name, $default); if ($name == 'result') { if ($variable !== null) { if (!$variable instanceof \ArrayObject) { throw new \RuntimeException('Variable result must be instance of ' . \ArrayObject::class . '. ' . gettype($variable) . ' given'); } $result = []; foreach ($variable as $entry) { if (!$entry instanceof EntityInterface) { throw new \RuntimeException('Variable result must be instance of ' . EntityInterface::class . '. ' . gettype($entry) . ' given'); } $result[] = $entry->extract(); } return $result; } } return $variable; }
public function getVariable($name, $default = null) { $changes = parent::getVariable('changes'); if (isset($changes[$name])) { return $changes[$name]; } if (strpos($name, 'changesErrors:') === 0) { $changesErrors = parent::getVariable('changesErrors', []); if (!empty($changesErrors)) { $explodedName = explode(':', $name); if (isset($explodedName[1])) { $elementName = $explodedName[1]; if (isset($changesErrors[$elementName])) { return $changesErrors[$elementName]; } } } } return parent::getVariable($name, $default); }
public function EventHandler(Console\Event $pEvent) { try { $console = $this->getServiceLocator()->get('console'); $config = $this->getServiceLocator()->get('Config'); if (true == $pEvent->getVerboseFlag()) { $console->write(' --------------- ', ColorInterface::LIGHT_GREEN); $console->writeLine('-----------------------------------------------------------', ColorInterface::YELLOW); $console->write(" [Listener] ", ColorInterface::LIGHT_GREEN); $console->writeLine(__CLASS__, ColorInterface::YELLOW); $console->write(' --------------- ', ColorInterface::LIGHT_GREEN); $console->writeLine('-----------------------------------------------------------', ColorInterface::YELLOW); } if (true == $pEvent->getVerboseFlag()) { $console->write(" [Template Key] "); $console->writeLine($this->mTemplateKey, ColorInterface::YELLOW); } // create the view model for the vhost template $view = new ViewModel(); $view->setTemplate($this->mTemplateKey); $vhost_config = $config['Installation']['Vhost']; $server = $vhost_config['Server']; $prefix = $server['Prefix']; $region = $server['Region']; $domain = $server['Domain']; $suffix = $server['Suffix']; $view->setVariable('ServerName', $prefix . $region . $domain . $suffix); $public = $server['PublicFolder']; $view->setVariable('DocumentRoot', getcwd() . '/' . $public); $view->setVariable('ApplicationEnv', $pEvent->getEnvironment()); $view->setVariable('Config', $vhost_config); if (true == $pEvent->getVerboseFlag()) { $console->write(" [Server Name] "); $console->writeLine($view->getVariable('ServerName'), ColorInterface::YELLOW); $console->write(" [Document Root] "); $console->writeLine($view->getVariable('DocumentRoot'), ColorInterface::YELLOW); $console->write(" [Environment] "); $console->writeLine($view->getVariable('ApplicationEnv'), ColorInterface::YELLOW); } // setup specific configurations $view->setVariable('ApacheLogDir', $vhost_config['ApacheLog']); $view->setVariable('UseSyslog', $vhost_config['UseSysLog']); $view->setVariable('Ports', $vhost_config['Ports']); $view->setVariable('CorsOrigin', false); if (array_key_exists('CorsOrigin', $config['Installation'])) { $cors = $config['Installation']['CorsOrigin']; if (false === is_array($cors)) { throw new Exception('CorsOrigin configuration must be an array.'); } $origin_list = implode('|', $cors); $view->setVariable('CorsOrigin', 'http(s)?://(' . $origin_list . ')'); } /** * Create a template map resolver from the template map in the config * file. * Using that we create a renderer that will parse the zf2 view * template like an ordinary template, so that we can get back its * contents */ $map = new TemplateMapResolver($config['view_manager']['template_map']); $renderer = new PhpRenderer(); $renderer->setResolver($map); // Rewrite/modsec rule additions $rewritePreView = new ViewModel(); $rewritePreView->setTemplate($this->mRewriteRulesPreTemplateKey); $rewritePreView->setVariable('Config', $vhost_config); $view->setVariable('RewritePreRules', $renderer->render($rewritePreView)); $rewritePostView = new ViewModel(); $rewritePostView->setTemplate($this->mRewriteRulesPostTemplateKey); $rewritePostView->setVariable('Config', $vhost_config); $view->setVariable('RewritePostRules', $renderer->render($rewritePostView)); $modSec = new ViewModel(); $modSec->setTemplate($this->mModsecTemplateKey); $modSec->setVariable('Config', $vhost_config); $view->setVariable('ModSecRules', $renderer->render($modSec)); if (true == $pEvent->getVerboseFlag()) { $console->write(" [View Template] "); $console->writeLine(realpath($map->get($this->mTemplateKey)), ColorInterface::YELLOW); } // write the vhost file here.... $vhost_extension = $server['Extension']; $vhost_path = $server['Path']; $vhost_filename = $view->getVariable('ServerName') . '.' . $vhost_extension; $vhost_file = $vhost_path . $vhost_filename; if (true == $pEvent->getVerboseFlag()) { $console->write(" [Apache VHost] "); $console->writeLine($vhost_file, ColorInterface::YELLOW); } if (false === is_dir($vhost_path)) { $result = mkdir($vhost_path, 0775, true); if (true === $result) { if (true == $pEvent->getVerboseFlag()) { $console->write(" [NOTICE] ", ColorInterface::LIGHT_CYAN); $console->writeLine("Vhost directory has been created.", ColorInterface::CYAN); } } else { if (true == $pEvent->getVerboseFlag()) { $console->write(" [Failure] ", ColorInterface::RED); $console->writeLine('Failed to create vhost directory, ' . $vhost_path . PHP_EOL, ColorInterface::RED); } throw new Exception('Failed to create vhost directory, ' . $vhost_path); } } if (false === is_writable($vhost_path)) { if (true == $pEvent->getVerboseFlag()) { $console->write(" [Failure] ", ColorInterface::RED); $console->writeLine("Vhost directory ({$vhost_path}) is not writable by web server." . PHP_EOL, ColorInterface::RED); } throw new Exception("Vhost directory ({$vhost_path}) is not writable by web server."); } if (file_exists($vhost_file) && false === $pEvent->getForceFlag()) { if (true == $pEvent->getVerboseFlag()) { $console->write(" [NOTICE] ", ColorInterface::LIGHT_CYAN); $console->writeLine('Apache VHost file already exists, skipping creation.', ColorInterface::CYAN); $console->write(" [INFO] ", ColorInterface::LIGHT_CYAN); $console->writeLine('To overwrite the existing file, use --force' . PHP_EOL, ColorInterface::CYAN); } } else { if (file_exists($vhost_file) && false === is_writable($vhost_file)) { if (true == $pEvent->getVerboseFlag()) { $console->write(" [Failure] ", ColorInterface::RED); $console->writeLine('Apache VHost Not Writable!' . PHP_EOL, ColorInterface::RED); } throw new Exception(sprintf('Virtual host file %s is not writable.', $vhost_file)); } else { $pointer = fopen($vhost_file, 'w+'); if ($pointer === false) { if (true == $pEvent->getVerboseFlag()) { $console->write(" [Failure] ", ColorInterface::RED); $console->writeLine('Failed to open Apache VHost for writing!' . PHP_EOL, ColorInterface::RED); } throw new Exception(sprintf('Failed to open Virtual host file %s for writing.', $vhost_file)); } else { fwrite($pointer, $renderer->render($view)); fclose($pointer); if (true == $pEvent->getVerboseFlag()) { $console->write(' [Success] ', ColorInterface::LIGHT_GREEN); $console->writeLine('VHost File Update Complete' . PHP_EOL, ColorInterface::YELLOW); /* adding some extra spacing for the notice outside of this if block */ $console->write(' '); } $notice = $console->colorize('[NOTICE] ', ColorInterface::LIGHT_CYAN); $response = new Response(); $response->setContent($notice . 'Virtual Host file has been updated, you may need to restart/reload your web server.'); return $response; } } } return NULL; } catch (Exception $e) { $response = new Response(); $response->setErrorLevel(1); $response->setContent('Exception Encountered: ' . $e->getMessage()); return $response; } }