/** * 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 Request $request incoming request */ public function invokeAction(Trace $trace, $action, Request $request) { 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'); } return $method->invoke($this, $trace, $request); }
/** * @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; }
/** * Create a new ArrayTrace at the insertion point * @param string $message text of the message * @param array $tags * @return ArrayTrace child trace object */ public function addChild($message, array $tags = null) { Preconditions::checkIsString($message, '$message should be string'); $child = new ArrayTrace($this->timer, $message); $this->children[] = array('info' => $this->getInfoArray(), 'type' => 'trace', 'trace' => $child); return $child; }
public function invokeAction(Trace $trace, $action, Request $request) { Preconditions::checkIsString($action); if (!$this->loginManager->isLoggedIn()) { throw new AuthenticationRequiredException(); } return parent::invokeAction($trace, $action, $request); }
public function __construct(array $options, $cookieFile) { Preconditions::checkIsString($cookieFile, '$cookieFile should be string'); $this->options = $options; $this->cookieFile = $cookieFile; $this->_curlInit(); $this->stats = new RequestStatisticsImpl(); }
/** * 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]; }
/** * 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']; }
/** * 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']; }
/** * 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; }
public function getOptionsFromHtml(Trace $trace, $aisResponseHtml, $elementId) { Preconditions::checkIsString($aisResponseHtml); Preconditions::checkIsString($elementId); $html = $this->fixProblematicTags($trace->addChild("Fixing html for better DOM parsing."), $aisResponseHtml); $domWholeHtml = $this->createDomFromHtml($trace, $html); $element = $this->findEnclosingElement($trace, $domWholeHtml, $elementId); // ok, now we have restricted document $options = $this->getOptions($trace->addChild("Get options"), $element); return $options; }
/** * 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 Request $request incoming request */ public function invokeAction(Trace $trace, $action, Request $request) { Preconditions::checkIsString($action); Preconditions::checkNotNull($request); $screenFactory = $this->factory; $register = $screenFactory->newRegisterPredmetovScreen($trace); $this->registerPredmetovScreen = $register; $result = parent::invokeAction($trace, $action, $request); if ($this->registerPredmetovScreen) { $this->registerPredmetovScreen->closeWindow(); } return $result; }
/** * 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 createTableFromHtml(Trace $trace, $aisResponseHtml, $dataViewName) { Preconditions::checkIsString($aisResponseHtml); Preconditions::checkIsString($dataViewName); $html = $this->fixProblematicTags($trace->addChild("Fixing html for better DOM parsing."), $aisResponseHtml); $domWholeHtml = $this->createDomFromHtml($trace, $html); $element = $this->findEnclosingElement($trace, $domWholeHtml, $dataViewName); $dom = new DOMDocument(); $dom->appendChild($dom->importNode($element, true)); // ok, now we have restricted document $headers = $this->getTableDefinition($trace->addChild("Get table definition"), $dom); $data = $this->getTableData($trace->addChild("Get table data"), $dom); return new DataTableImpl($headers, $data); }
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; }
public function warnWrongTableStructure(Trace $trace, $tableName, array $expectedDefinition, array $definition) { Preconditions::checkIsString($tableName); if ($expectedDefinition != $definition) { $message = array('type' => 'unexpectedTableStructure', 'tableName' => $tableName); $this->addWarning($message); $child = $trace->addChild("Differences in data table " . $tableName); list($del, $both, $ins) = FajrUtils::compareArrays($expectedDefinition, $definition); $child->tlogVariable('deleted', $del); $child->tlogVariable('unchanged', $both); $child->tlogVariable('inserted', $ins); $child->tlogVariable('expectedDefinition', $expectedDefinition); $child->tlogVariable('definition', $definition); } }
/** * 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); }
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; }
/** * Returns xml request code just for this actionComponent * * Sample of xml: * * <events> * <ev> * <dlgName>VSES017_StudentZapisneListyDlg0</dlgName> * <compName>nacitatDataAction</compName> * <event class='avc.ui.event.AVCActionEvent'> * </ev> * </events> * * @return DOMDocument XML object */ public function getActionXML($dlgName) { Preconditions::checkIsString($dlgName); $xml_spec = new DOMDocument(); $dlgName = $xml_spec->createElement('dlgName', $dlgName); $events = $xml_spec->createElement('events'); $ev = $xml_spec->createElement('ev'); $compName = $xml_spec->createElement('compName', $this->componentID); $event = $xml_spec->createElement('event'); $atr = $xml_spec->createAttribute("class"); $atr->value = 'avc.ui.event.AVCActionEvent'; $event->appendChild($atr); $ev->appendChild($dlgName); $ev->appendChild($compName); $ev->appendChild($event); $events->appendChild($ev); $xml_spec->appendChild($events); return $xml_spec; }
/** * 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 should be string.'); $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; }
public function validate($data) { Preconditions::checkIsString($data, '$data should be string.'); return true; }
/** * Converts ais portal's Windows-1250 encoding to UTF-8. * * @param string $html in Windows-1250 * * @returns string $html in UTF-8 */ private function convertEncoding($html) { Preconditions::checkIsString($html); if (strpos($html, 'UTF-8') !== false) { return $html; } return @iconv("WINDOWS-1250", "UTF-8", $html); }
/** * Create a comboBox and set its comboBoxName * * @param string $comboBoxName name of comboBox which we want to store here */ public function __construct($comboBoxName) { Preconditions::checkIsString($comboBoxName); $this->comboBoxName = $comboBoxName; }
/** * Removes data associated with key from database. * * @param string key * * @returns mixed removed value */ public function remove($key) { Preconditions::checkIsString($key); $ret = $this->read($key); if (!$this->deleteStatement) { $this->deleteStatement = $this->prepareDelete(); } $statement = $this->deleteStatement; $statement->bindValue('key', $key); if (!$statement->execute()) { throw new sfStorageException("Problem writing into key '{$key}'"); } return $ret; }
/** * Sets value of parameter identified by $key * * @param string $key * @param mixed $value * * @returns void */ public function setParameter($key, $value) { $this->assertInitialized(); Preconditions::checkIsString($key); $this->inputParameters[$key] = $value; }
/** * Creates array with elements parsed from html containing information list. * * @param string $aisResponseHtml * * @returns complete array with parsed data from html * @throws ParseException on failure of creating DOM from html */ public function parseHtml(Trace $trace, $aisResponseHtml) { Preconditions::checkIsString($aisResponseHtml); $html = self::fixBr($trace, $aisResponseHtml); $domWholeHtml = ParserUtils::createDomFromHtml($trace, $html); $domWholeHtml->preserveWhiteSpace = false; //ziskanie nazvu skoly, jedina vec co chcem ziskat co sa nenachadza v tabulke $b = $domWholeHtml->getElementsByTagName("b"); $trace->tlog("Finding first element with tag name 'b'"); $bb = $b->item(0); if ($bb !== null) { $this->spracujB($trace, $bb); } $trNodes = $domWholeHtml->getElementsByTagName("tr"); $trace->tlog("Getting all elements with tag name 'tr'"); // prechadzam vsetkymi <tr> tagmi $firstTr = true; foreach ($trNodes as $tr) { // nechcem uplne prvy tag co je v tr, za <b> je iba nazov: informacny list if ($firstTr) { $firstTr = false; continue; } $trace->tlog("Getting all elements with tag name 'td'"); $tdNodes = $tr->getElementsByTagName("td"); // prechadzam <td> tagmi foreach ($tdNodes as $td) { if (!$td->hasChildNodes()) { continue; } $trace->tlog("Getting all child nodes of element 'td'"); foreach ($td->childNodes as $final) { if ($final->nodeType != \XML_ELEMENT_NODE) { continue; } if ($final->tagName == 'b') { $trace->tlog("Parsing node with tag name 'b'"); $this->spracujB($trace, $final); } else { if ($final->tagName == 'div') { $trace->tlog("Parsing node with tag name 'div'"); $this->parseDiv($trace, $final); } } } } } }
/** * Set value of parameter. * * @param string $key key to the data * @param mixed $data * * @returns void */ public function setParameter($key, $data) { Preconditions::checkIsString($key); $this->data[$key] = $data; }
/** * Fix non-breakable spaces which were converted to special character during parsing. * * @param string $str string to fix * * @returns string fixed string */ private function fixNbsp($str) { Preconditions::checkIsString($str); // special fix for // xml decoder decodes into special utf-8 character // TODO(ppershing): nehodili by sa tie niekedy dalej v aplikacii niekedy? $nbsp = chr(0xc2) . chr(0xa0); return str_replace($nbsp, ' ', $str); }
/** * Writes information about current Trace event * */ private function writeEntry($parent, $logMsg, $userData, $tags) { Preconditions::checkIsString($logMsg); $caller = TraceUtil::getCallerData(2); $class = isset($caller['class']) ? $caller['class'] : "N/A"; $class = preg_replace("@.*\\\\@", "", $class); $function = isset($caller['function']) ? $caller['function'] : 'N/A'; $caller = TraceUtil::getCallerData(1); $file = isset($caller['file']) ? $caller['file'] : 'N/A'; $line = isset($caller['line']) ? $caller['line'] : 'N/A'; $traceInfo = array('elapsed' => $this->timer->getElapsedTime(), 'timestamp' => time(), 'class' => $class, 'function' => $function, 'file' => $file, 'line' => $line); if ($tags != null) { $traceInfo = array_merge($tags, $traceInfo); } $serialized = $this->stream->serialize($logMsg); $serialized .= $this->stream->serialize($traceInfo); $serialized .= $this->stream->serialize($userData); $id = $this->stream->writeEntry(EntryStream::ENTRY_TRACE, $parent, $serialized); return $id; }
/** * Return the length of string in bytes * @param string $str */ public static function byteLength($str) { Preconditions::checkIsString($str); $overloadMode = ini_get('mbstring.func_overload'); if (($overloadMode & 2) == 2) { // overloaded string functions // strlen returns # of chars instead of bytes in this case // so we use mb_strlen return mb_strlen($str, '8bit'); } return strlen($str); }