/** * Invoke an action given its name * * This function requests information necessary to operate on * VSES017 AIS application * * @param Trace $trace trace object * @param string $action action name * @param Context $context fajr context */ public function invokeAction(Trace $trace, $action, Context $context) { $request = $context->getRequest(); $response = $context->getResponse(); Preconditions::checkIsString($action); $this->screenFactory = new VSES017\VSES017_factory($context->getAisConnection()); $this->adminStudia = $this->screenFactory->newAdministraciaStudiaScreen($trace); $this->studium = $request->getParameter('studium', '0'); $this->zoznamStudii = $this->adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:")); $this->zapisneListy = $this->adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), $this->studium); $this->zapisnyList = $request->getParameter('list'); if (empty($this->zapisnyList)) { $tmp = $this->zapisneListy->getData(); $lastList = end($tmp); $this->zapisnyList = $lastList['index']; } $this->terminyHodnoteniaScreen = $this->screenFactory->newTerminyHodnoteniaScreen($trace, $this->adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList), $this->adminStudia->getStudiumIdFromZapisnyListIndex($trace, $this->zapisnyList)); // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne // objekty, ktore v konstruktore robia requesty $this->hodnoteniaScreen = $this->screenFactory->newHodnoteniaPriemeryScreen($trace, $this->adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList)); $response->set('zoznamStudii', $this->zoznamStudii); $response->set('studium', $this->studium); $response->set('zapisneListy', $this->zapisneListy); $response->set('zapisnyList', $this->zapisnyList); parent::invokeAction($trace, $action, $context); }
/** * Create a new ArrayTrace at the insertion point * @param string $header text to use as header * @return ArrayTrace child trace object */ public function addChild($header = "") { Preconditions::checkIsString($header, 'header'); $child = new ArrayTrace($this->timer, $header); $this->children[] = array('info' => $this->getInfoArray(), 'type' => 'trace', 'trace' => $child); return $child; }
/** * @param string $proxyDir path to directory containing cosign proxy files */ public function __construct($proxyDir, $proxyCookieName) { Preconditions::checkIsString($proxyDir, 'proxyDir'); Preconditions::checkIsString($proxyDir, 'proxyCookieName'); $this->proxyDir = $proxyDir; $this->proxyCookieName = $proxyCookieName; }
public function __construct(array $options, $cookieFile) { Preconditions::checkIsString($cookieFile, '$cookieFile should be string'); $this->options = $options; $this->cookieFile = $cookieFile; $this->_curlInit(); }
/** * Invoke an action given its name * * This function checks if public non-abstract non-static runAction method * exists in this object and calls it in such a case with request and response * parameters * * @param Trace $trace trace object * @param string $action action name * @param Context $context fajr context */ public function invokeAction(Trace $trace, $action, Context $context) { Preconditions::checkIsString($action); Preconditions::checkMatchesPattern('@^[A-Z][a-zA-Z]*$@', $action, '$action must start with capital letter and ' . 'contain only letters.'); $methodName = 'run' . $action; if (!method_exists($this, $methodName)) { throw new Exception('Action method ' . $methodName . ' does not exist'); } $method = new ReflectionMethod($this, $methodName); if (!$method->isPublic()) { throw new Exception('Action method ' . $methodName . ' is not public'); } if ($method->isAbstract()) { throw new Exception('Action method ' . $methodName . ' is abstract'); } if ($method->isStatic()) { throw new Exception('Action method ' . $methodName . ' is static'); } if ($method->isConstructor()) { throw new Exception('Action method ' . $methodName . ' is constructor'); } if ($method->isDestructor()) { throw new Exception('Action method ' . $methodName . ' is destructor'); } $method->invoke($this, $trace, $context); }
/** * Invoke an action given its name * * This function requests information necessary to operate on * VSES017 AIS application * * @param Trace $trace trace object * @param string $action action name * @param Context $context fajr context */ public function invokeAction(Trace $trace, $action, Context $context) { Preconditions::checkIsString($action); $request = $context->getRequest(); $response = $context->getResponse(); $session = $context->getSessionStorage(); // check access to application if (!in_array(AIS2ApplicationEnum::ADMINISTRACIA_STUDIA, $session->read('ais/aisApps'))) { $response->setTemplate('studium/notAvailable'); return; } $screenFactory = $this->factory; $adminStudia = $screenFactory->newAdministraciaStudiaScreen($trace); $this->studium = $request->getParameter('studium', '0'); $this->zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:")); $this->zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), $this->studium); FajrUtils::warnWrongTableStructure($response, 'zoznam studii', regression\ZoznamStudiiRegression::get(), $this->zoznamStudii->getTableDefinition()); FajrUtils::warnWrongTableStructure($response, 'zoznam zapisnych listov', regression\ZoznamZapisnychListovRegression::get(), $this->zapisneListy->getTableDefinition()); $this->zapisnyList = $request->getParameter('list'); if ($this->zapisnyList === '') { $tmp = $this->zapisneListy->getData(); $lastList = end($tmp); $this->zapisnyList = $lastList['index']; } $this->terminyHodnoteniaScreen = $screenFactory->newTerminyHodnoteniaScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList), $adminStudia->getStudiumIdFromZapisnyListIndex($trace, $this->zapisnyList)); // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne // objekty, ktore v konstruktore robia requesty $this->hodnoteniaScreen = $screenFactory->newHodnoteniaPriemeryScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList)); $response->set('zoznamStudii', $this->zoznamStudii); $response->set('studium', $this->studium); $response->set('zapisneListy', $this->zapisneListy); $response->set('zapisnyList', $this->zapisnyList); parent::invokeAction($trace, $action, $context); }
/** * @param string $proxyDir path to directory containing cosign proxy files */ public function __construct($proxyDir, $proxyCookieName) { Preconditions::checkIsString($proxyDir, '$proxyDir should be string.'); Preconditions::checkIsString($proxyCookieName, '$proxyCookieName should be string'); $this->proxyDir = $proxyDir; $this->proxyCookieName = $proxyCookieName; }
/** * @param string $name name of the skin to retrieve * * @returns SkinConfig * @throws IllegalArgumentException */ public function getSkinByName($name) { Preconditions::checkIsString($name); if (!in_array($name, array_keys($this->skins))) { throw new IllegalArgumentException("You must specify a valid skin!"); } return $this->skins[$name]; }
public function write($string) { Preconditions::checkIsString($string, '$string must be string'); $this->checkNotClosed(); if (@fwrite($this->handle, $string) === false) { throw new Exception("Cannot write file"); } }
/** * Parses user name from AIS2 start page * * @param string $html AIS2 html reply to be parsed * * @returns AIS2Version AIS2 version * @throws ParseException on error */ public function parseUserNameFromMainPage($html) { Preconditions::checkIsString($html); $data = StrUtil::matchAll(self::USERNAME_PATTERN, $html); if ($data === false) { throw new ParseException("Cannot parse username from response."); } return $data['username']; }
/** * Parses the AIS2 version from html page. * * @param string $html AIS2 html reply to be parsed * * @returns AIS2Version AIS2 version * @throws ParseException on error */ public function parseVersionStringFromMainPage($html) { Preconditions::checkIsString($html); $data = StrUtil::matchAll(self::VERSION_PATTERN, $html); if ($data === false) { throw new ParseException("Cannot parse AIS version from response."); } return new AIS2Version(2, $data['major'], $data['minor'], $data['patch']); }
/** * Deserialize previously serialized value. * * @param string $data * * @returns mixed deserialized value */ public static function deserialize($data) { Preconditions::checkIsString($data); $result = @unserialize($data); if ($result == false || !array_key_exists('value', $result)) { throw new InvalidArgumentException("Invalid data to deserialize."); } return $result['value']; }
/** * Get a value of a given key * @param string $key * @returns mixed value of a given key * @throws InvalidArgumentException if the key does not exist */ public function get($key) { Preconditions::checkIsString($key); // Note: isset() returns false if the item value is null if (!array_key_exists($key, $this->config)) { throw new InvalidArgumentException('Unknown configuration parameter: ' . $key); } return $this->config[$key]; }
/** * Invoke an action given its name * * This function requests information necessary to operate on * VSES017 AIS application * * @param Trace $trace trace object * @param string $action action name * @param Context $context fajr context */ public function invokeAction(Trace $trace, $action, Context $context) { Preconditions::checkIsString($action); $request = $context->getRequest(); $response = $context->getResponse(); $session = $context->getSessionStorage(); Preconditions::checkNotNull($request); Preconditions::checkNotNull($response); Preconditions::checkNotNull($session); // check access to application $apps = $session->read('ais/aisApps'); if (!is_array($apps)) { throw new Exception("Interná chyba - zoznam AIS aplikácii je nekorektný."); } if (!in_array(AIS2ApplicationEnum::ADMINISTRACIA_STUDIA, $apps)) { $response->setTemplate('studium/notAvailable'); return; } $screenFactory = $this->factory; $adminStudia = $screenFactory->newAdministraciaStudiaScreen($trace); $this->administraciaStudiaScreen = $adminStudia; $this->studium = $request->getParameter('studium', '0'); $this->zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:")); $this->zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), $this->studium); FajrUtils::warnWrongTableStructure($trace, $response, 'zoznam studii', regression\ZoznamStudiiRegression::get(), $this->zoznamStudii->getTableDefinition()); FajrUtils::warnWrongTableStructure($trace, $response, 'zoznam zapisnych listov', regression\ZoznamZapisnychListovRegression::get(), $this->zapisneListy->getTableDefinition()); $zapisneListyData = $this->zapisneListy->getData(); if (count($zapisneListyData) == 0) { $this->zapisnyList = null; $this->terminyHodnoteniaScreen = null; $this->hodnoteniaScreen = null; } else { $this->zapisnyList = $request->getParameter('list'); if ($this->zapisnyList === '') { $lastList = end($zapisneListyData); $this->zapisnyList = $lastList['index']; } $this->terminyHodnoteniaScreen = $screenFactory->newTerminyHodnoteniaScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_TERMINY_HODNOTENIA), $adminStudia->getStudiumIdFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_TERMINY_HODNOTENIA)); // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne // objekty, ktore v konstruktore robia requesty $this->hodnoteniaScreen = $screenFactory->newHodnoteniaPriemeryScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_HODNOTENIA_PRIEMERY)); } $response->set('zoznamStudii', $this->zoznamStudii); $response->set('studium', $this->studium); $response->set('zapisneListy', $this->zapisneListy); $response->set('zapisnyList', $this->zapisnyList); if (array_key_exists($action, $this->actionInfo)) { $info = $this->actionInfo[$action]; if ($info['requiresZapisnyList'] && $this->zapisnyList == null) { $response->set('activeTab', $info['tabName']); $response->setTemplate('studium/chybaZapisnyList'); return; } } parent::invokeAction($trace, $action, $context); }
/** * Removes data from this storage. * * @param string $key key to the data * * @returns mixed data associated with the key */ public function remove($key) { Preconditions::checkIsString($key); $retval = null; if (array_key_exists($key, $this->data)) { $retval = $this->data[$key]; unset($this->data[$key]); } return $retval; }
/** * Parses ais html into DOM. * * @param Trace $trace * @param string $html * * @returns DOMDocument parsed DOM * @throws ParseException on failure */ public static function createDomFromHtml(Trace $trace, $html) { Preconditions::checkIsString($html); $dom = new DOMDocument(); $trace->tlog("Loading html to DOM"); $loaded = @$dom->loadHTML($html); if (!$loaded) { throw new ParseException("Problem parsing html to DOM."); } $trace->tlog('Fixing id attributes in the DOM'); ParserUtils::fixIdAttributes($trace, $dom); return $dom; }
public function validate($data) { Preconditions::checkIsString($data, '$data should be string.'); if (strlen($data) > 0 && $data[0] == '-' && $this->signed) { $data = substr($data, 1); } if (!ctype_digit($data)) { throw new ValidationException("Číslo obsahuje neplatné znaky."); } if (strlen($data) >= 9) { throw new ValidationException("Číslo je príliš dlhé."); } return true; }
/** * Zarata predmet s danou znamkou * @param string $znamkaText nazov znamky (A, B, ...), moze byt aj prazdny, * vtedy sa zarata ako neohodnoteny predmet * @param float $kredity pocet kreditov, ktore sa maju zaratat * @throws InvalidArgumentException ak dana znamka nie je platna */ public function add($znamkaText, $kredity) { Preconditions::checkContainsInteger($kredity); Preconditions::check($kredity >= 0, "Kreditov musí byť nezáp**ný počet."); Preconditions::checkIsString($znamkaText); if ($znamkaText == '') { $this->addNeohodnotene($kredity); return; } $znamka = Znamka::fromString($znamkaText); if ($znamka === null) { throw new InvalidArgumentException("Známka '{$znamkaText}' nie je platná"); } $this->addOhodnotene($znamka->getNumerickaHodnota(), $kredity); }
public function add($znamka, $kredity) { Preconditions::checkContainsInteger($kredity); Preconditions::check($kredity >= 0, "Kreditov musí byť nezáp**ný počet."); Preconditions::checkIsString($znamka); if (isset(PriemeryInternal::$numerickaHodnotaZnamky[$znamka])) { $hodnota = PriemeryInternal::$numerickaHodnotaZnamky[$znamka]; $this->addOhodnotene($hodnota, $kredity); } else { if ($znamka === '') { $this->addNeohodnotene($kredity); } else { throw new InvalidArgumentException("Známka '{$znamka}' nie je platná"); } } }
/** * Get the names of all available ais applications * from ais menu. * * @param Trace $trace * @param array(string) $modules module names to check * * @returns array(string) names of applications */ public function getAllAvailableApplications(Trace $trace, array $modules) { foreach ($modules as $module) { Preconditions::checkIsString($module, '$modules must be an array of strings'); } $trace->tlog('getting available applications'); $moduleApps = array('ES' => array(AIS2ApplicationEnum::ADMINISTRACIA_STUDIA)); $apps = array(); foreach ($modules as $module) { if (array_key_exists($module, $moduleApps)) { $apps = array_merge($apps, $moduleApps[$module]); } } // remove duplicates return array_values($apps); }
/** * Invoke an action given its name * * This function lookups the controller to be used in a lookup table, * tries to instantiate it and dispatch the request * * @param Trace $trace trace object * @param string $action action name * @param Context $context fajr context */ public function invokeAction(Trace $trace, $action, Context $context) { Preconditions::checkIsString($action); $parts = explode('.', $action, 2); if (count($parts) != 2) { throw new Exception('Action name does not contain "."'); } if (empty($this->classNameTable[$parts[0]])) { throw new Exception('Could not find a mapping for action ' . $action); } $className = $this->classNameTable[$parts[0]]; $instance = new $className(); if (!$instance instanceof Controller) { throw new Exception('Class "' . $className . '" mapped to action "' . $action . '" is not a controller'); } $instance->invokeAction($trace->addChild('Target action ' . $parts[1]), $parts[1], $context); }
public function getFullPath(array $options, $tableName) { Preconditions::checkIsString($tableName); Preconditions::check($tableName != '', "Table name must be non-empty"); $path = ''; $options = array_merge($this->options, $options); foreach ($options as $key => $value) { $pathSegment = $key . $value; if (!preg_match(self::ALLOWED_CHARS_REGEX, $pathSegment)) { throw IllegalArgumentException('Invalid characters in options'); } $path .= '/' . $pathSegment; } if (!preg_match(self::ALLOWED_CHARS_REGEX, $tableName)) { throw IllegalArgumentException('Invalid characters in tableName'); } return $path .= '/' . $tableName; }
/** * Parse a file for cosign proxy cookies * * @param Trace $trace trace object * @param string $filename * @returns array Array of parsed service cookies indexed by name */ public function parseFile(Trace $trace, $filename) { Preconditions::checkIsString($filename, 'filename'); $cookies = array(); $subTrace = $trace->addChild('Parsing cosign proxy file'); $subTrace->tlogVariable('filename', $filename); @($file = file($filename)); if ($file === false) { $subTrace->tlog('failed'); throw new ParseException('Cannot read proxy file'); } foreach ($file as $lineContent) { $parsed = $this->parseString($subTrace, trim($lineContent)); if (isset($cookies[$parsed->getName()])) { throw new ParseException('Duplicate proxy service entry found ' . 'while parsing proxy cookies'); } $cookies[$parsed->getName()] = $parsed; } return $cookies; }
/** * Invoke an action given its name * * This function requests information necessary to operate on * VSST060 AIS application * * @param Trace $trace trace object * @param string $action action name * @param Context $context fajr context */ public function invokeAction(Trace $trace, $action, Context $context) { Preconditions::checkIsString($action); $request = $context->getRequest(); $response = $context->getResponse(); $session = $context->getSessionStorage(); Preconditions::checkNotNull($request); Preconditions::checkNotNull($response); Preconditions::checkNotNull($session); // check access to application $apps = $session->read('ais/aisApps'); if (!is_array($apps)) { throw new Exception("Interná chyba - zoznam AIS aplikácii je nekorektný."); } if (!in_array(AIS2ApplicationEnum::REGISTER_PREDMETOV, $apps)) { $response->setTemplate('predmety/notAvailable'); return; } $screenFactory = $this->factory; $register = $screenFactory->newRegisterPredmetovScreen($trace); $this->registerPredmetovScreen = $register; parent::invokeAction($trace, $action, $context); }
/** * Get a value of a given key * @param string $key * @returns mixed value of a given key * @throws InvalidArgumentException if the key does not exist */ public static function get($key) { self::assertInitialized(); Preconditions::checkIsString($key); // Note: isset() returns false if the item value is null if (!array_key_exists($key, self::$config)) { throw new InvalidArgumentException('Unknown configuration parameter: ' . $key); } return self::$config[$key]; }
/** * Ensure a parameter is not set after this call * * @param string $name parameter name to clear */ public function clearParameter($name) { Preconditions::checkIsString($name, '$name should be string.'); $this->input->set($name, null); }
/** * Checks whether $haystack ends with a substring $needle * * @param string $haystack * @param string $needle * * @returns bool true if $haystack ends with $needle, false otherwise */ public static function endsWith($haystack, $needle) { Preconditions::checkIsString($haystack); Preconditions::checkIsString($needle); if ($needle == '') { return true; } $needle_length = strlen($needle); if ($needle_length > strlen($haystack)) { return false; } return substr_compare($haystack, $needle, -$needle_length, $needle_length) === 0; }
/** * Set a template name to be used * * Note that the rendering subsystem may choose the actual template * used based on other parameters as well. * * @param string $template template name */ public function setTemplate($template) { Preconditions::checkIsString($template, '$template should be string.'); $this->template = $template; }
/** * Ensure a parameter is not set after this call * * @param string $name parameter name to clear */ public function clearParameter($name) { Preconditions::checkIsString($name, 'name'); Input::set($name, null); }
/** * Return configured parameter value. * @deprecated If possible, use injector to inject * instances of initialized objects. * * @param string $name name of the parameter to return * * @returns mixed configured value */ public function getParameter($name) { Preconditions::checkIsString($name); assert($this->container->hasParameter($name)); return $this->container->getParameter($name); }