Exemplo n.º 1
0
 public function runInformacnyList(Trace $trace, Request $request)
 {
     $searchCode = $request->getParameter('code');
     $format = $request->getParameter('format');
     Preconditions::check(!empty($searchCode), "Nezadaný kód predmetu!");
     // Zistime aktualny akad rok.
     $akadRok = FajrUtils::getAcademicYear();
     $content = $this->registerPredmetovScreen->getInformacnyList($trace, $searchCode, $akadRok);
     // Docasny fix, vrati PDF s informacnym listom
     $response = new \Symfony\Component\HttpFoundation\Response($content, 200);
     $response->headers->set('Content-Type', 'application/pdf');
     return $response;
     $ip = new InformacnyListParser();
     $list = $ip->parse($trace, $content);
     $params = array();
     $params['list'] = $list->getAllAttributes();
     $params['code'] = $searchCode;
     $name = $list->getAttribute('nazov');
     $code = $list->getAttribute('kod');
     if ($code === false) {
         $code = $searchCode;
     } else {
         $code = $code['values'][0];
     }
     if ($name === false) {
         $name = 'Predmet ' . $code;
     } else {
         $name = $name['values'][0];
     }
     $params['subjectName'] = $name;
     return $this->renderResponse('predmety/informacnyList', $params, $format == 'json' ? 'json' : 'html');
 }
Exemplo n.º 2
0
 /**
  * Returns a securely generated random *bytes* using the supplied providers.
  * Providers will be queried in the same order as the were given to constructor
  * and first which will return random bytes will be used.
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes generated bytes
  * @throws RuntimeException if any error occurs (or no provider returns random bytes)
  *    Warning: Never catch and ignore exceptions from this function!
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     // TODO(ppershing): verify following claim
     // Try the OpenSSL method first. This is the strongest.
     $output = false;
     foreach ($this->providers as $provider) {
         $output = $provider->randomBytes($count);
         if ($output !== false) {
             break;
         }
     }
     // No method was able to generate random bytes.
     // Do not ignore this and throw security error as
     // caller may forgot to check return value.
     if ($output == false) {
         throw new RuntimeException("Unable to generate random bytes.");
     }
     // internal check on sanity
     if (strlen($output) != $count) {
         throw new Exception("Wrong number random bytes were generated. " . "This may be a severe internal error in secure random.");
     }
     return $output;
 }
 /**
  * Returns a securely generated random bytes from windows cryptoapi.
  *
  * Warning: use SecureRandom::random() instead
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes|false generated bytes or false on error
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     if (!self::isAvailable()) {
         return false;
     }
     $util = new COM(self::CRYPTOAPI_COM);
     $base64 = $util->GetRandom($count, 0);
     // default encoding is base64
     $output = base64_decode($base64, true);
     // be strict
     return $output;
 }
 /**
  * Returns a securely generated random bytes from linux random.
  *
  * Warning: use SecureRandom::random() instead
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes|false generated bytes or false on error
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     if (!self::isAvailable()) {
         return false;
     }
     $handle = @fopen(self::RANDOM_FILE, 'rb');
     $output = @fread($handle, $count);
     @fclose($handle);
     if (strlen($output) !== $count) {
         return false;
         // oops, some problem reading required number of bytes
     }
     return $output;
 }
 /**
  * Returns a securely generated random bytes from open SSL.
  *
  * Warning: use SecureRandom::random() instead
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes|false generated bytes or false on error
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     if (!self::isAvailable()) {
         return false;
     }
     // TODO(ppershing): check this on windows: from user comments in manual page:
     // FYI, openssl_random_pseudo_bytes() can be incredibly slow under Windows, to the point of being
     // unusable.
     $output = openssl_random_pseudo_bytes($count, $strong);
     if ($strong === true) {
         // openssl claim the random is strong
         return $output;
     }
     return false;
 }
Exemplo n.º 6
0
 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;
 }
 /**
  * Initialize this storage instance.
  *
  * Available options:
  *  * permanent_storage: sfStorage, required
  *  * temporary_storage: sfStorage, required
  *
  * @param array $options An associative array of options
  *
  * @returns bool true, if initialization completes successfully
  */
 public function initialize($options = array())
 {
     parent::initialize($options);
     // $options are now available as $this->options
     if (!isset($this->options[self::PERMANENT])) {
         throw new sfInitializationException('You must provide a "' . self::PERMANENT . '" option to FileStorage.');
     }
     Preconditions::check($this->options[self::PERMANENT] instanceof sfStorage, 'Permanent storage must be instance of sfStorage');
     if (!isset($this->options[self::TEMPORARY])) {
         throw new sfInitializationException('You must provide a "' . self::TEMPORARY . '" option to FileStorage.');
     }
     Preconditions::check($this->options[self::TEMPORARY] instanceof sfStorage, 'Temporary storage must be instance of sfStorage');
     if (($initialKeys = $this->options[self::TEMPORARY]->read(self::KEY)) !== null) {
         $this->changedKeys = $initialKeys;
     } else {
         $this->changedKeys = array();
     }
 }
Exemplo n.º 8
0
 /**
  * Constructs settings object. Omitting $settingsStorage will
  * result in "unmodifiable and default" settings.
  *
  * @param FajrConfig $config fajr configuration
  * @param sfStorage $settingsStorage user settings storage
  */
 public function __construct(FajrConfig $config, sfStorage $settingsStorage = null)
 {
     $this->settingsStorage = $settingsStorage;
     $allSkins = $config->get(FajrConfigOptions::TEMPLATE_SKINS);
     foreach ($allSkins as $skin) {
         Preconditions::check($skin instanceof SkinConfig);
     }
     $skins = array();
     foreach ($allSkins as $key => $skin) {
         if (!$skin->isInternal()) {
             $skins[$key] = $skin;
         }
     }
     $this->skins = $skins;
     $default = $config->get(FajrConfigOptions::TEMPLATE_DEFAULT_SKIN);
     if (!in_array($default, array_keys($this->skins))) {
         throw new RuntimeException("Default skin is not available!");
     }
     $this->defaultSkinName = $default;
 }
Exemplo n.º 9
0
 /**
  * Compute square of the argument
  *
  * @param numeric $value
  *
  * @returns numeric $value * $value
  */
 public static function sqr($value)
 {
     Preconditions::check(is_numeric($value));
     return $value * $value;
 }
Exemplo n.º 10
0
 public function writeEntry($type, $parent, $data)
 {
     Preconditions::checkIsString($type);
     /* Entry type is defined to be 2-bytes long so check that */
     Preconditions::check(StrUtil::byteLength($type) == 2);
     Preconditions::checkIsNumber($parent);
     Preconditions::checkIsString($data);
     $id = $this->nextEntryId++;
     $this->write('BE');
     $this->write($type);
     $this->write(pack('nnN', $id, $parent, StrUtil::byteLength($data)));
     $this->write($data);
     $this->flush();
     return $id;
 }
Exemplo n.º 11
0
 /**
  * Compute the p-value of  null-hypothesis holds.
  *
  * Warning: please read
  * http://en.wikipedia.org/wiki/P-value#Frequent_misunderstandings
  * or consult statistician how to interpret results.
  *
  * @param int $degreesOfFreedom If you have 1-D histogram
  *    analysis, $degreesOfFreedom should be number of bins-1.
  *    For other scenarios, please consult statistician.
  * @param double $chisqr result of chi-square test
  *
  * @returns double p-value.
  */
 static function pvalue($degreesOfFreedom, $chisqr)
 {
     Preconditions::check(is_int($degreesOfFreedom));
     Preconditions::check($degreesOfFreedom > 0);
     Preconditions::checkIsNumber($chisqr);
     Preconditions::check($chisqr >= 0);
     return Gamma::regularizedGammaQ($degreesOfFreedom / 2.0, $chisqr / 2.0);
 }
Exemplo n.º 12
0
 public function testCheckFail()
 {
     $this->setExpectedException("InvalidArgumentException");
     Preconditions::check(2 > 4, "Plainly wrong");
 }
Exemplo n.º 13
0
 /**
  * Prida predmet s danou znamkou, zarata do neohodnotenych ak
  * sa znamku nepodarilo rozpoznat alebo nie je vyplnena
  * @param string $castRoka do ktorej casti roka sa ma znamka zaratat
  * @param string $znamkaText nazov znamky (A, B, ...)
  * @param int $kredity pocet kreditov pre danu znamku
  */
 public function add($castRoka, $znamkaText, $kredity)
 {
     Preconditions::check(in_array($castRoka, array(self::SEMESTER_LETNY, self::SEMESTER_ZIMNY, self::AKADEMICKY_ROK)), "Neplatná časť študijného roka.");
     $znamka = null;
     if ($znamkaText !== '') {
         $znamka = Znamka::fromString($znamkaText);
     }
     $this->obdobia[$castRoka]->add($kredity, $znamka);
     // Ak pridavame do akademickeho roka, tak hodnotu nechceme zaratat dvakrat
     if ($castRoka !== self::AKADEMICKY_ROK) {
         $this->obdobia[self::AKADEMICKY_ROK]->add($kredity, $znamka);
     }
 }