Пример #1
0
 /**
  * @ignore
  */
 public function __set($name, $value)
 {
     // The purpose of this method is to detect references to undeclared object variables (properties) in
     // implementations of non-static methods, where the name of the undeclared variable could be resulting from
     // a typo.
     assert('false', vs(isset($this), get_defined_vars()));
 }
Пример #2
0
 /**
  * Encodes a data with Base64 encoding and returns the result.
  *
  * @param  data $data The data to be encoded.
  *
  * @return CUStringObject The encoded data.
  */
 public static function encode($data)
 {
     assert('is_cstring($data)', vs(isset($this), get_defined_vars()));
     $encodedData = base64_encode($data);
     assert('is_cstring($encodedData)', vs(isset($this), get_defined_vars()));
     return $encodedData;
 }
Пример #3
0
 protected static function hashTypeToString($hashType)
 {
     switch ($hashType) {
         case self::MD2:
             return "md2";
         case self::MD4:
             return "md4";
         case self::MD5:
             return "md5";
         case self::SHA1:
             return "sha1";
         case self::SHA224:
             return "sha224";
         case self::SHA256:
             return "sha256";
         case self::SHA384:
             return "sha384";
         case self::SHA512:
             return "sha512";
         case self::RIPEMD128:
             return "ripemd128";
         case self::RIPEMD160:
             return "ripemd160";
         case self::RIPEMD256:
             return "ripemd256";
         case self::RIPEMD320:
             return "ripemd320";
         case self::WHIRLPOOL:
             return "whirlpool";
         case self::TIGER128_3:
             return "tiger128,3";
         case self::TIGER160_3:
             return "tiger160,3";
         case self::TIGER192_3:
             return "tiger192,3";
         case self::TIGER128_4:
             return "tiger128,4";
         case self::TIGER160_4:
             return "tiger160,4";
         case self::TIGER192_4:
             return "tiger192,4";
         case self::SNEFRU:
             return "snefru";
         case self::SNEFRU256:
             return "snefru256";
         case self::GOST:
             return "gost";
         case self::ADLER32:
             return "adler32";
         case self::CRC32:
             return "crc32";
         case self::CRC32B:
             return "crc32b";
         case self::FNV132:
             return "fnv132";
         case self::FNV164:
             return "fnv164";
         case self::JOAAT:
             return "joaat";
         case self::HAVAL128_3:
             return "haval128,3";
         case self::HAVAL160_3:
             return "haval160,3";
         case self::HAVAL192_3:
             return "haval192,3";
         case self::HAVAL224_3:
             return "haval224,3";
         case self::HAVAL256_3:
             return "haval256,3";
         case self::HAVAL128_4:
             return "haval128,4";
         case self::HAVAL160_4:
             return "haval160,4";
         case self::HAVAL192_4:
             return "haval192,4";
         case self::HAVAL224_4:
             return "haval224,4";
         case self::HAVAL256_4:
             return "haval256,4";
         case self::HAVAL128_5:
             return "haval128,5";
         case self::HAVAL160_5:
             return "haval160,5";
         case self::HAVAL192_5:
             return "haval192,5";
         case self::HAVAL224_5:
             return "haval224,5";
         case self::HAVAL256_5:
             return "haval256,5";
         default:
             assert('false', vs(isset($this), get_defined_vars()));
     }
 }
Пример #4
0
 /**
  * In a string, escapes all characters that have a special meaning in the regular expression domain, and returns
  * the escaped string.
  *
  * With this method, you can prepare an arbitrary string to be used as a part of a regular expression.
  *
  * @param  string $string The string to be escaped.
  * @param  string $delimiter **OPTIONAL. Default is** "/". The pattern delimiter that is going to be used by the
  * resulting regular expression and therefore needs to be escaped as well.
  *
  * @return string The escaped string.
  */
 public static function enterTd($string, $delimiter = self::DEFAULT_PATTERN_DELIMITER)
 {
     assert('is_cstring($string) && is_cstring($delimiter)', vs(isset($this), get_defined_vars()));
     return preg_quote($string, $delimiter);
 }
Пример #5
0
 /**
  * @ignore
  */
 public static function isNameIcuCompatible($name)
 {
     assert('is_cstring($name)', vs(isset($this), get_defined_vars()));
     $itz = IntlTimeZone::createTimeZone($name);
     return CString::equals($name, $itz->getID());
 }
Пример #6
0
 protected function finalize()
 {
     $res = fclose($this->m_file);
     assert('$res', vs(isset($this), get_defined_vars()));
     $this->m_done = true;
 }
Пример #7
0
 public static function setMailing(CMail $mail, $minTimeBetweenSendMailHours = self::DEFAULT_MIN_TIME_BETWEEN_SEND_MAIL_HOURS)
 {
     // Enables mailing about encountered errors with the provided CMail object.
     assert('is_int($minTimeBetweenSendMailHours)', vs(isset($this), get_defined_vars()));
     assert('$minTimeBetweenSendMailHours >= 0', vs(isset($this), get_defined_vars()));
     self::$ms_mailing = true;
     self::$ms_mail = $mail;
     self::$ms_minTimeBetweenSendMailHours = $minTimeBetweenSendMailHours;
     self::registerHandlers();
 }
Пример #8
0
 /**
  * Translates a string out of the XML text domain, replacing all XML entities with their literal equivalents.
  *
  * Both double and single quotes are translated.
  *
  * @param  string $string The string to be translated.
  *
  * @return CUStringObject The translated string.
  */
 public static function leaveTdAll($string)
 {
     assert('is_cstring($string)', vs(isset($this), get_defined_vars()));
     return html_entity_decode($string, ENT_QUOTES, "UTF-8");
 }
Пример #9
0
 /**
  * Converts a floating-point quantity of mass from one unit into another and returns the result.
  *
  * @param  float $quantity The quantity to be converted.
  * @param  enum $fromUnit The source unit.
  * @param  enum $toUnit The destination unit.
  *
  * @return float The converted quantity.
  */
 public static function convertMassf($quantity, $fromUnit, $toUnit)
 {
     assert('is_float($quantity) && is_enum($fromUnit) && is_enum($toUnit)', vs(isset($this), get_defined_vars()));
     assert('$quantity >= 0.0', vs(isset($this), get_defined_vars()));
     if ($fromUnit == $toUnit) {
         return $quantity;
     }
     $milligramQty;
     switch ($fromUnit) {
         case self::MILLIGRAM:
             $milligramQty = $quantity;
             break;
         case self::GRAM:
             $milligramQty = $quantity * 1000;
             break;
         case self::KILOGRAM:
             $milligramQty = $quantity * 1000000;
             break;
         case self::TON:
             $milligramQty = $quantity * 1000000000;
             break;
         case self::OUNCE:
             $milligramQty = $quantity * 28349.5231;
             break;
         case self::POUND:
             $milligramQty = $quantity * 453592.37;
             break;
         case self::STONE:
             $milligramQty = $quantity * 6350293.18;
             break;
         case self::SHORT_TON:
             $milligramQty = $quantity * 907184740;
             break;
         case self::LONG_TON:
             $milligramQty = $quantity * 1016046908.8;
             break;
         default:
             assert('false', vs(isset($this), get_defined_vars()));
             break;
     }
     $outputQty;
     switch ($toUnit) {
         case self::MILLIGRAM:
             $outputQty = $milligramQty;
             break;
         case self::GRAM:
             $outputQty = $milligramQty / 1000;
             break;
         case self::KILOGRAM:
             $outputQty = $milligramQty / 1000000;
             break;
         case self::TON:
             $outputQty = $milligramQty / 1000000000;
             break;
         case self::OUNCE:
             $outputQty = $milligramQty / 28349.5231;
             break;
         case self::POUND:
             $outputQty = $milligramQty / 453592.37;
             break;
         case self::STONE:
             $outputQty = $milligramQty / 6350293.18;
             break;
         case self::SHORT_TON:
             $outputQty = $milligramQty / 907184740;
             break;
         case self::LONG_TON:
             $outputQty = $milligramQty / 1016046908.8;
             break;
         default:
             assert('false', vs(isset($this), get_defined_vars()));
             break;
     }
     return $outputQty;
 }
Пример #10
0
 /**
  * Replaces any reference to one of the framework's special directories in a path with the directory's actual path
  * and returns the usable path.
  *
  * A framework's directory is referenced in a path by wrapping its ID into double curly braces, as in
  * "{{PHRED_PATH_TO_FRAMEWORK_ROOT}}", optionally with "/" after the reference.
  *
  * @param  string $path The path to the file or directory (can be absolute or relative).
  *
  * @return CUStringObject The usable path.
  */
 public static function frameworkPath($path)
 {
     assert('!isset($path) || is_cstring($path)', vs(isset($this), get_defined_vars()));
     if (!isset($path)) {
         return null;
     }
     // Replace every "{{EXAMPLE_PATH}}" in the path string with the value of "EXAMPLE_PATH" key from $GLOBALS
     // variable if such key exists in the variable.
     $modified = false;
     $path = CRegex::replaceWithCallback($path, "/\\{\\{\\w+\\}\\}/", function ($matches) use(&$modified) {
         $pathVarName = CString::substr($matches[0], 2, CString::length($matches[0]) - 4);
         if (isset($GLOBALS[$pathVarName])) {
             $modified = true;
             return $GLOBALS[$pathVarName] . "/";
         } else {
             assert('false', vs(isset($this), get_defined_vars()));
             return $matches[0];
         }
     });
     if ($modified) {
         $path = CRegex::replace($path, "/\\/{2,}/", "/");
     }
     return $path;
 }
Пример #11
0
 /**
  * Repeats an element for a specified number of times and returns the resulting array.
  *
  * For instance, an element of "a" repeated three times would result in an array of "a", "a", "a".
  *
  * @param  mixed $element The element to be repeated.
  * @param  int $times The length of the resulting array.
  *
  * @return CArray The resulting array.
  */
 public static function repeat($element, $times)
 {
     assert('is_int($times)', vs(isset($this), get_defined_vars()));
     assert('$times > 0', vs(isset($this), get_defined_vars()));
     $resArray = self::make($times);
     for ($i = 0; $i < $times; $i++) {
         $resArray[$i] = $element;
     }
     return $resArray;
 }
Пример #12
0
 /**
  * Repeats a string for a specified number of times and returns the resulting string.
  *
  * For instance, the string of "a" repeated three times would result in "aaa".
  *
  * @param  string $string The string to be repeated.
  * @param  int $times The number of times for the string to be repeated.
  *
  * @return string The resulting string.
  */
 public static function repeat($string, $times)
 {
     assert('is_cstring($string) && is_int($times)', vs(isset($this), get_defined_vars()));
     assert('$times > 0 || (self::isEmpty($string) && $times == 0)', vs(isset($this), get_defined_vars()));
     return str_repeat($string, $times);
 }
Пример #13
0
 protected static function patternEnumToString($pattern)
 {
     switch ($pattern) {
         case self::PATTERN_DEFAULT:
             return "Y-m-d H:i:s e";
         case self::PATTERN_DEFAULT_DATE:
             return "Y-m-d";
         case self::PATTERN_DEFAULT_TIME:
             return "H:i:s";
         case self::PATTERN_ATOM:
             return "Y-m-d\\TH:i:sP";
         case self::PATTERN_COOKIE:
             return "l, d-M-y H:i:s T";
         case self::PATTERN_HTTP_HEADER_GMT:
             return "D, d M Y H:i:s T";
         case self::PATTERN_ISO8601:
             return "Y-m-d\\TH:i:sO";
         case self::PATTERN_MYSQL:
             return "Y-m-d H:i:s";
         case self::PATTERN_RFC822:
             return "D, d M y H:i:s O";
         case self::PATTERN_RFC850:
             return "l, d-M-y H:i:s T";
         case self::PATTERN_RFC1036:
             return "D, d M y H:i:s O";
         case self::PATTERN_RFC2822:
             return "D, d M Y H:i:s O";
         case self::PATTERN_RFC3339:
             return "Y-m-d\\TH:i:sP";
         case self::PATTERN_RSS:
             return "D, d M Y H:i:s O";
         case self::PATTERN_W3C:
             return "Y-m-d\\TH:i:sP";
         default:
             assert('false', vs(isset($this), get_defined_vars()));
     }
 }
Пример #14
0
 /**
  * @ignore
  */
 public static function onThirdPartyUpdateByPackageManager()
 {
     if (!self::isInCliMode()) {
         // This method can be run in CLI mode only.
         assert('false', vs(isset($this), get_defined_vars()));
     }
     $timeoutPause = new CTimeoutPause();
     CShell::speak("Processing third-party components ...");
     $tpDps = CFile::listDirectories(CFilePath::absolute($GLOBALS["PHRED_PATH_TO_THIRD_PARTY"]));
     $ignorePackages = CConfiguration::option("upd.thirdPartyOopWrappingIgnorePackages");
     $ignorePackagesL2 = CArray::filter($ignorePackages, function ($package) {
         return CString::find($package, "/");
     });
     $newTpDps = CArray::make();
     $len = CArray::length($tpDps);
     for ($i = 0; $i < $len; $i++) {
         $tpDp = $tpDps[$i];
         $dirName = CFilePath::name($tpDp);
         if (!CArray::find($ignorePackages, $dirName)) {
             $dpHasL2DirsToIgnore = CArray::find($ignorePackagesL2, $dirName, function ($packageL2, $dirName) {
                 return CString::equals(CFilePath::directory($packageL2), $dirName);
             });
             if (!$dpHasL2DirsToIgnore) {
                 CArray::push($newTpDps, $tpDp);
             } else {
                 $tpSubDps = CFile::listDirectories($tpDp);
                 $tpSubDps = CArray::filter($tpSubDps, function ($subDp) use($ignorePackagesL2) {
                     return !CArray::find($ignorePackagesL2, $subDp, function ($packageL2, $subDp) {
                         return CString::endsWith($subDp, $packageL2);
                     });
                 });
                 CArray::pushArray($newTpDps, $tpSubDps);
             }
         }
     }
     $tpDps = $newTpDps;
     $wrapProtectedMethods = CConfiguration::option("upd.thirdPartyOopWrappingInProtectedMethods");
     $wrapPrivateMethods = CConfiguration::option("upd.thirdPartyOopWrappingInPrivateMethods");
     static $s_stdPhpTag = "<?php";
     static $s_progressResolution = 0.05;
     $prevProgressDivR = 0;
     $tpDpsLen = CArray::length($tpDps);
     for ($i0 = 0; $i0 < $tpDpsLen; $i0++) {
         $tpFps = CFile::reFindFilesRecursive($tpDps[$i0], "/\\.php\\d?\\z/");
         $tpFpsLen = CArray::length($tpFps);
         for ($i1 = 0; $i1 < $tpFpsLen; $i1++) {
             $fileCode = CFile::read($tpFps[$i1]);
             if (!CString::find($fileCode, self::$ms_thirdPartyAlreadyOopWrappedMark)) {
                 $parser = new PhpParser\Parser(new PhpParser\Lexer());
                 try {
                     // Parse the code.
                     $statements = $parser->parse($fileCode);
                     // Wrap the code into OOP.
                     $traverser = new PhpParser\NodeTraverser();
                     $mainVisitor = new CMainVisitor($wrapProtectedMethods, $wrapPrivateMethods);
                     $traverser->addVisitor($mainVisitor);
                     $statements = $traverser->traverse($statements);
                     $wrappedCode = (new PhpParser\PrettyPrinter\Standard())->prettyPrint($statements);
                     $phpTagPos = CString::indexOf($wrappedCode, $s_stdPhpTag);
                     if ($phpTagPos == -1) {
                         $wrappedCode = "{$s_stdPhpTag}\n\n{$wrappedCode}";
                         $phpTagPos = 0;
                     }
                     $wrappedCode = CString::insert($wrappedCode, $phpTagPos + CString::length($s_stdPhpTag), "\n\n" . self::$ms_thirdPartyAlreadyOopWrappedMark);
                     // Save.
                     CFile::write($tpFps[$i1], $wrappedCode);
                 } catch (PhpParser\Error $parserError) {
                     CShell::say("\nPhpParser: " . $tpFps[$i1] . ", at line " . $parserError->getRawLine() . ": " . $parserError->getRawMessage());
                 }
             }
             $progress = (double) ($i0 / $tpDpsLen + 1 / $tpDpsLen * $i1 / $tpFpsLen);
             $progressDivR = CMathi::floor($progress / $s_progressResolution);
             if ($progressDivR != $prevProgressDivR) {
                 $perc = CMathi::round($progressDivR * $s_progressResolution * 100);
                 CShell::speak("{$perc}%");
             }
             $prevProgressDivR = $progressDivR;
         }
     }
     CShell::speak("100%");
     CShell::say("Done.");
     $timeoutPause->end();
 }
Пример #15
0
 /**
  * In a string, removes percent-encoding (URL encoding) from all characters encoded according to the older flavor
  * of percent-encoding and returns the new string.
  *
  * According to the older flavor of percent-encoding, the space character is decoded from either "+" or "%20"
  * (literal spaces are not permitted in a valid URL), "+" from "%2B" only, and "~" from either "%7E" or "~". This
  * flavor of percent-encoding is primarily used with query strings in URLs and with
  * "application/x-www-form-urlencoded" data in POST requests. In any other place, the newer flavor of
  * percent-encoding is usually preferred.
  *
  * @param  string $string The string to be translated out of the URL text domain.
  *
  * @return CUStringObject The translated string.
  */
 public static function leaveTdOld($string)
 {
     assert('is_cstring($string)', vs(isset($this), get_defined_vars()));
     return urldecode($string);
 }
Пример #16
0
 protected static function recurseValueBeforeFiltering($value, $inputFilterOrFilterCollection, &$success, $currDepth)
 {
     assert('$inputFilterOrFilterCollection instanceof CInputFilter || ' . 'is_collection($inputFilterOrFilterCollection)', vs(isset($this), get_defined_vars()));
     if ($currDepth == self::$ms_maxRecursionDepth) {
         $success = false;
         return;
     }
     $currDepth++;
     if (!is_cmap($value)) {
         // Only interested in PHP arrays.
         return $value;
     }
     if (is_carray($inputFilterOrFilterCollection)) {
         // The output value is expected to be a CArray; the keys in the arrived PHP array should be sequential.
         if (!CMap::areKeysSequential($value)) {
             $success = false;
             return;
         }
         $value = CArray::fromPArray($value);
         $len = CArray::length($value);
         if ($len != CArray::length($inputFilterOrFilterCollection)) {
             $success = false;
             return;
         }
         for ($i = 0; $i < $len; $i++) {
             $inputValue = $value[$i];
             $inputFilterElement = $inputFilterOrFilterCollection[$i];
             $inputValue = self::recurseValueBeforeFiltering($inputValue, $inputFilterElement, $success, $currDepth);
             if (!$success) {
                 return;
             }
             $value[$i] = $inputValue;
         }
     } else {
         if (is_cmap($inputFilterOrFilterCollection)) {
             // The output value is expected to be a CMap; already got one.
             foreach ($value as $inputKey => &$inputValue) {
                 if (!CMap::hasKey($inputFilterOrFilterCollection, $inputKey)) {
                     $success = false;
                     return;
                 }
                 $inputFilterElement = $inputFilterOrFilterCollection[$inputKey];
                 $inputValue = self::recurseValueBeforeFiltering($inputValue, $inputFilterElement, $success, $currDepth);
                 if (!$success) {
                     return;
                 }
             }
             unset($inputValue);
         } else {
             $success = false;
             return;
         }
     }
     return $value;
 }
Пример #17
0
 /**
  * @ignore
  */
 public function isReturnTransferSet()
 {
     // To be used by "friend" classes only.
     assert('isset($this->m_isReturnTransferSet)', vs(isset($this), get_defined_vars()));
     return $this->m_isReturnTransferSet;
 }
Пример #18
0
 /**
  * Adds a component to a URL path.
  *
  * @param  string $component The component to be added. All the characters in the component's string should be
  * represented literally and none of the characters should be percent-encoded.
  *
  * @return void
  */
 public function addComponent($component)
 {
     assert('is_cstring($component)', vs(isset($this), get_defined_vars()));
     CArray::push($this->m_components, $component);
 }
Пример #19
0
 /**
  * Sends a message to the recipient(s).
  *
  * @param  reference $failedAddresses **OPTIONAL. OUTPUT.** After the method is called with this parameter
  * provided, the parameter's value, which is of type `CArrayObject`, is an array containing the email addresses of
  * the recipients who failed to receive the message.
  *
  * @return int The number of recipients who have successfully received the message.
  */
 public function send(&$failedAddresses = null)
 {
     assert('isset($this->m_swiftMailer) && isset($this->m_swiftMessage)', vs(isset($this), get_defined_vars()));
     assert('(isset($this->m_from) || isset($this->m_sender) || isset($this->m_returnAddress)) && ' . '(isset($this->m_to) || isset($this->m_cc) || isset($this->m_bcc))', vs(isset($this), get_defined_vars()));
     $message = $this->m_swiftMessage;
     if (isset($this->m_from)) {
         $message->setFrom($this->m_from);
     }
     if (isset($this->m_to)) {
         $message->setTo($this->m_to);
     }
     if (isset($this->m_cc)) {
         $message->setCc($this->m_cc);
     }
     if (isset($this->m_bcc)) {
         $message->setBcc($this->m_bcc);
     }
     if (isset($this->m_sender)) {
         $message->setSender($this->m_sender);
     }
     if (isset($this->m_returnAddress)) {
         $message->setReturnPath($this->m_returnAddress);
     }
     if (isset($this->m_replyAddress)) {
         $message->setReplyTo($this->m_replyAddress);
     }
     if (isset($this->m_body)) {
         if (CString::equals($this->m_bodyType, CMimeType::PLAIN_TEXT)) {
             $this->m_body = $this->maybeWrapText($this->m_body);
         }
         $message->setBody($this->m_body, $this->m_bodyType);
     }
     if (isset($this->m_altBodiesAndTypes)) {
         $len = CArray::length($this->m_altBodiesAndTypes);
         for ($i = 0; $i < $len; $i++) {
             $bodyAndType = $this->m_altBodiesAndTypes[$i];
             $body = $bodyAndType[0];
             $type = $bodyAndType[1];
             if (CString::equals($type, CMimeType::PLAIN_TEXT)) {
                 $body = $this->maybeWrapText($body);
             }
             $message->addPart($body, $type);
         }
     }
     $paFailedAddresses;
     $res = $this->m_swiftMailer->send($message, $paFailedAddresses);
     if (is_cmap($paFailedAddresses)) {
         $failedAddresses = oop_a(CArray::fromPArray($paFailedAddresses));
     }
     $res = is_int($res) ? $res : 0;
     return $res;
 }
Пример #20
0
 /**
  * @ignore
  */
 public function offsetUnset($offset)
 {
     assert('false', vs(isset($this), get_defined_vars()));
 }
Пример #21
0
 /**
  * Exits the script with a specified status.
  *
  * @param  bool $statusIsOk `true` if the script has run successfully, `false` if not.
  * @param  bool $writeNewlineToLog **OPTIONAL. Default is** `true`. If logging is enabled, tells whether the
  * current entries in the log file should be concluded with a newline.
  *
  * @return void
  */
 public static function exitScript($statusIsOk, $writeNewlineToLog = true)
 {
     assert('is_bool($statusIsOk) && is_bool($writeNewlineToLog)', vs(isset($this), get_defined_vars()));
     if ($writeNewlineToLog && isset(self::$ms_logFp)) {
         self::writeToLog("\n");
     }
     $exitCode = $statusIsOk ? 0 : 1;
     exit($exitCode);
 }
Пример #22
0
<?php

$page_file = "viewschedule.php";
$page_title = "View Schedule";
require "ext/main_fns.php";
require "ext/header.php";
require "ext/schedule_fns.php";
open_db();
if (!$_SESSION["logged_in"]) {
    loginPrompt($_POST[username], $_POST[remember_me], $_SESSION["error"]);
} else {
    /*----- CONTENT ------*/
    ?>
<div id="cp">
<center><h1>Schedule</h1>

<?php 
    vs();
    ?>
</center>
<br>
<a href="cp.php"> << Back to Control Panel</a>
</div>

<?php 
}
require "ext/footer.php";
Пример #23
0
 protected static function compressionLevelEnumToGZip($compressionLevel)
 {
     switch ($compressionLevel) {
         case self::FASTEST:
             return 1;
         case self::FAST:
             return 3;
         case self::NORMAL:
             return 6;
         case self::MAXIMUM:
             return 9;
         default:
             assert('false', vs(isset($this), get_defined_vars()));
     }
 }
Пример #24
0
 /**
  * Determines the order in which two values should appear in a place where it matters, assuming the ascending
  * order.
  *
  * If the values are objects of your custom class, the class should conform to the
  * [IEqualityAndOrder](IEqualityAndOrder.html) interface.
  *
  * @param  mixed $value0 The first value for comparison.
  * @param  mixed $value1 The second value for comparison.
  *
  * @return int A negative value (typically `-1`) if the first value should go before the second value, a positive
  * value (typically `1`) if the other way around, and `0` if the two values are equal.
  *
  * @link   IEqualityAndOrder.html IEqualityAndOrder
  */
 public static function orderAsc($value0, $value1)
 {
     if (CDebug::isDebugModeOn()) {
         if (!(is_cstring($value0) && is_cstring($value1) || is_carray($value0) && is_carray($value1) || is_cmap($value0) && is_cmap($value1))) {
             // With the above exceptions, the two values should be both either scalars or objects of the same
             // class.
             assert('is_object($value0) == is_object($value1)', vs(isset($this), get_defined_vars()));
             assert('!is_object($value0) || CString::equals(get_class($value0), get_class($value1))', vs(isset($this), get_defined_vars()));
         }
     }
     $className;
     if (!phred_classify_duo($value0, $value1, $className)) {
         // Compare the values as scalars.
         assert('(is_scalar($value0) || is_null($value0)) && (is_scalar($value1) || is_null($value1))', vs(isset($this), get_defined_vars()));
         return $value0 === $value1 ? 0 : ($value0 < $value1 ? -1 : 1);
     } else {
         // Compare the values as objects that may conform to one of the comparison interfaces.
         $reflClass = new ReflectionClass($className);
         if ($reflClass->implementsInterface("IEqualityAndOrderStatic")) {
             $res = call_user_func([$className, "compare"], $value0, $value1);
             assert('is_int($res)', vs(isset($this), get_defined_vars()));
             return $res;
         }
         if ($reflClass->implementsInterface("IEqualityAndOrder")) {
             $res = call_user_func([$value0, "compare"], $value1);
             assert('is_int($res)', vs(isset($this), get_defined_vars()));
             return $res;
         }
         // The class of the objects being compared does not implement any applicable comparison interfaces.
         assert('false', vs(isset($this), get_defined_vars()));
     }
 }
Пример #25
0
 /**
  * Determines if a locale name is valid and known.
  *
  * Scripts, variants, and keyword-value pairs are ignored.
  *
  * @param  string $localeName The locale name to be looked into.
  *
  * @return bool `true` if the locale name is valid and known, `false` otherwise.
  */
 public static function isValid($localeName)
 {
     assert('is_cstring($localeName)', vs(isset($this), get_defined_vars()));
     if (!CRegex::findGroups($localeName, "/^([a-z]{2,3}(?![^_\\-]))(?|[_\\-]([a-z]{2,3}(?![^_\\-]))|[_\\-][a-z]{4}(?![^_\\-])[_\\-]([a-z]{2,3}" . "(?![^_\\-]))|(?:\\z|[_\\-][a-z])).*\\z(?<=[a-z0-9])/i", $foundGroups)) {
         return false;
     }
     $rfc2616 = $foundGroups[0];
     if (CArray::length($foundGroups) > 1) {
         $rfc2616 .= "-" . $foundGroups[1];
     }
     return is_cstring(Locale::acceptFromHttp($rfc2616));
 }
Пример #26
0
 /**
  * Strips HTML and PHP tags from a string and returns the resulting string.
  *
  * @param  string $string The input string.
  *
  * @return CUStringObject The resulting string.
  */
 public static function stripTags($string)
 {
     assert('is_cstring($string)', vs(isset($this), get_defined_vars()));
     return strip_tags($string);
 }
Пример #27
0
 /**
  * @ignore
  */
 public static function fromPArray($pArray)
 {
     assert('is_array($pArray)', vs(isset($this), get_defined_vars()));
     $map = new self(true);
     $map->m_map = $pArray;
     return $map;
 }
Пример #28
0
 /**
  * @ignore
  */
 protected static function normFormToNc($form)
 {
     switch ($form) {
         case self::NF_C:
             return Normalizer::FORM_C;
         case self::NF_D:
             return Normalizer::FORM_D;
         case self::NF_KC:
             return Normalizer::FORM_KC;
         case self::NF_KD:
             return Normalizer::FORM_KD;
         default:
             assert('false', vs(isset($this), get_defined_vars()));
     }
 }
Пример #29
0
 /**
  * Inserts a value into a map under the next integer key.
  *
  * This method could serve as a more eloquent alternative when dealing with interfaces that are using the PHP's
  * associative array in the role of a regular array.
  *
  * The new value is inserted under the integer key that is greater by one compared to the greatest integer key
  * already in the map or under `0` if there were no integer keys.
  *
  * @param  map $map The map to be modified.
  * @param  mixed $value The value to be inserted.
  *
  * @return void
  */
 public static function insertValue(&$map, $value)
 {
     assert('is_cmap($map)', vs(isset($this), get_defined_vars()));
     if (is_array($map)) {
         array_push($map, $value);
     } else {
         $pArray =& $map->toPArray();
         array_push($pArray, $value);
     }
 }
Пример #30
-1
 /**
  * Starts a session by sending out the added requests.
  *
  * @param  reference $success **OPTIONAL. OUTPUT.** After the method is called with this parameter provided, the
  * parameter's value tells whether the session was successful.
  *
  * @return void
  */
 public function start(&$success = null)
 {
     $success = true;
     if ($this->m_hasError) {
         $success = false;
         return;
     }
     if (CArray::isEmpty($this->m_requestRecordsQueue)) {
         // Nothing to do.
         return;
     }
     // Current policy is to disable HTTP pipelining.
     $res = curl_multi_setopt($this->m_multiCurl, CURLMOPT_PIPELINING, 0);
     if (!$res) {
         // Should never get in here as long as cURL options are being set correctly, hence the assertion.
         assert('false', vs(isset($this), get_defined_vars()));
         $this->m_hasError = true;
         $this->m_errorMessage = "The 'curl_multi_setopt' function failed.";
         $success = false;
         $this->finalize();
         return;
     }
     $anySuccessfulRequests = false;
     // Disable the script's execution timeout before getting into the session.
     $timeoutPause = new CTimeoutPause();
     $numRunningRequests = 0;
     // also the index of the next request to send
     while (true) {
         // From the request queue, add as many normal cURL handles to the multi cURL handle as it is allowed by the
         // maximum number of concurrent requests, priorly setting internal options for every request.
         while ($numRunningRequests < CArray::length($this->m_requestRecordsQueue) && $numRunningRequests < $this->m_maxNumConcurrentRequests) {
             $requestRecord = $this->m_requestRecordsQueue[$numRunningRequests];
             $request = $requestRecord[0];
             $onCompleteCallback = $requestRecord[1];
             $newCookieSession = $requestRecord[2];
             $requestCurl = $request->curl();
             // Set cURL options for the normal cURL handle, having created a temporary file for cookie storage if
             // needed.
             $requestSetOptSuccess;
             if ($this->m_cookiesAreEnabled && $request->isHttp()) {
                 if (!isset($this->m_cookiesFp)) {
                     $this->m_cookiesFp = CFile::createTemporary();
                 }
                 $request->setInternalOptions($requestSetOptSuccess, $this->m_cookiesFp, $newCookieSession);
             } else {
                 $request->setInternalOptions($requestSetOptSuccess);
             }
             if (!$requestSetOptSuccess) {
                 if (isset($onCompleteCallback)) {
                     call_user_func($onCompleteCallback, false, "", $request, $this);
                 }
                 CArray::remove($this->m_requestRecordsQueue, $numRunningRequests);
                 continue;
             }
             // Add the normal cURL handle to the multi cURL handle.
             $res = curl_multi_add_handle($this->m_multiCurl, $requestCurl);
             if ($res != 0) {
                 $this->m_hasError = true;
                 $curlError = curl_multi_strerror($res);
                 $this->m_errorMessage = is_cstring($curlError) && !CString::isEmpty($curlError) ? $curlError : "The 'curl_multi_add_handle' function failed.";
                 $success = false;
                 $timeoutPause->end();
                 $this->finalize();
                 return;
             }
             $numRunningRequests++;
         }
         if ($numRunningRequests == 0) {
             break;
         }
         // Process the currently added requests until complete or no more data is available. Although
         // `CURLM_CALL_MULTI_PERFORM` is deprecated since libcurl 7.20, keep it for compatibility reasons.
         $numRunningTransfers;
         do {
             $multiExecRes = curl_multi_exec($this->m_multiCurl, $numRunningTransfers);
         } while ($multiExecRes == CURLM_CALL_MULTI_PERFORM);
         if ($multiExecRes != CURLM_OK) {
             $this->m_hasError = true;
             $curlError = curl_multi_strerror($multiExecRes);
             $this->m_errorMessage = is_cstring($curlError) && !CString::isEmpty($curlError) ? $curlError : "The 'curl_multi_exec' function failed.";
             $success = false;
             $timeoutPause->end();
             $this->finalize();
             return;
         }
         // Check for completed requests, call the callback function for any completed one (if such a function is
         // defined), finalize completed requests, and remove completed requests from the queue.
         while (true) {
             $completedRequestInfo = curl_multi_info_read($this->m_multiCurl);
             if (!is_cmap($completedRequestInfo)) {
                 break;
             }
             // A request has completed.
             assert('$completedRequestInfo["msg"] == CURLMSG_DONE', vs(isset($this), get_defined_vars()));
             $requestCurl = $completedRequestInfo["handle"];
             $requestRes = $completedRequestInfo["result"];
             $requestRecordPos;
             $found = CArray::find($this->m_requestRecordsQueue, $requestCurl, function ($requestRecord, $requestCurl) {
                 $request = $requestRecord[0];
                 return $request->curl() == $requestCurl;
             }, $requestRecordPos);
             assert('$found', vs(isset($this), get_defined_vars()));
             $requestRecord = $this->m_requestRecordsQueue[$requestRecordPos];
             $request = $requestRecord[0];
             $onCompleteCallback = $requestRecord[1];
             // Remove the normal cURL handle from the multi cURL handle.
             $res = curl_multi_remove_handle($this->m_multiCurl, $requestCurl);
             if ($res != 0) {
                 $this->m_hasError = true;
                 $curlError = curl_multi_strerror($res);
                 $this->m_errorMessage = is_cstring($curlError) && !CString::isEmpty($curlError) ? $curlError : "The 'curl_multi_remove_handle' function failed.";
                 $success = false;
                 $timeoutPause->end();
                 $this->finalize();
                 return;
             }
             if ($requestRes == CURLE_OK) {
                 // The request has succeeded.
                 if (isset($onCompleteCallback)) {
                     $response;
                     if ($request->isReturnTransferSet()) {
                         $response = curl_multi_getcontent($requestCurl);
                         assert('is_cstring($response)', vs(isset($this), get_defined_vars()));
                     } else {
                         $response = "";
                     }
                     $request->onRequestCompleteOk();
                     // also close the normal cURL handle
                     call_user_func($onCompleteCallback, true, $response, $request, $this);
                 } else {
                     $request->onRequestCompleteOk();
                     // also close the normal cURL handle
                 }
                 $anySuccessfulRequests = true;
             } else {
                 // The request has failed.
                 $curlError = curl_strerror($requestRes);
                 if (!is_cstring($curlError)) {
                     $curlError = "";
                 }
                 $request->onRequestCompleteWithError($curlError);
                 // also close the normal cURL handle
                 if (isset($onCompleteCallback)) {
                     call_user_func($onCompleteCallback, false, "", $request, $this);
                 }
             }
             CArray::remove($this->m_requestRecordsQueue, $requestRecordPos);
             $numRunningRequests--;
         }
         assert('$numRunningRequests == $numRunningTransfers', vs(isset($this), get_defined_vars()));
         if ($numRunningTransfers > 0) {
             // Some requests are still being processed (by remote machines). Wait for more data to appear on
             // sockets, without getting hard on the CPU.
             do {
                 $multiSelectRes = curl_multi_select($this->m_multiCurl);
             } while ($multiSelectRes == -1);
         } else {
             // No requests are being processed. Check if any requests are pending.
             if (CArray::isEmpty($this->m_requestRecordsQueue)) {
                 // No requests are pending.
                 break;
             }
         }
     }
     // Set the script's execution time limit like the session has never happened.
     $timeoutPause->end();
     if (!$anySuccessfulRequests) {
         $this->m_hasError = true;
         $this->m_errorMessage = "None of the session's requests succeeded.";
         $success = false;
     }
     $this->finalize();
 }