Exemplo n.º 1
0
 /**
  * Returns the variants of a locale.
  *
  * @return CArrayObject The locale's variants of type `CUStringObject` (always uppercased).
  */
 public function variants()
 {
     assert('$this->hasVariants()', vs(isset($this), get_defined_vars()));
     $variants = Locale::getAllVariants($this->m_name);
     if (is_cmap($variants)) {
         return oop_a(CArray::fromPArray($variants));
     } else {
         return oop_a(CArray::make());
     }
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 public function testFromPArray()
 {
     $map = [0 => "a", 1 => "b", 3 => "c", 9 => "d"];
     $array = CArray::fromPArray($map);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c", "d")));
 }
Exemplo n.º 4
0
 public function leaveNode(PhpParser\Node $node)
 {
     if ($node instanceof PhpParser\Node\Stmt\Class_ || $node instanceof PhpParser\Node\Stmt\Trait_) {
         $this->m_numEnteredClassesOrTraits--;
     } else {
         if ($node instanceof PhpParser\Node\Stmt\Interface_) {
             $this->m_numEnteredInterfaces--;
         } else {
             if ($node instanceof PhpParser\Node\Stmt\ClassMethod) {
                 $numEnteredMethods = $this->m_numEnteredMethods;
                 $this->m_numEnteredMethods--;
                 if (!($this->m_numEnteredClassesOrTraits == 1 && $this->m_numEnteredInterfaces == 0 && $numEnteredMethods == 1 && $this->m_numEnteredClosures == 0 && $this->m_numEnteredFunctions == 0)) {
                     return;
                 }
                 $method = $node;
                 if ($method->isProtected() && !$this->m_wrapProtectedMethods && !$this->m_isTrait || $method->isPrivate() && !$this->m_wrapPrivateMethods && !$this->m_isTrait || $method->isAbstract()) {
                     return;
                 }
                 if (!isset($method->stmts) || CMap::isEmpty($method->stmts)) {
                     return;
                 }
                 $hasParams = false;
                 $params = CArray::make();
                 $hasParamsByRef = false;
                 $paramsByRef = CArray::make();
                 if (isset($method->params) && !CMap::isEmpty($method->params)) {
                     $hasParams = true;
                     $params = CArray::fromPArray($method->params);
                     $paramsByRef = CArray::filter($params, function ($param) {
                         return $param->byRef;
                     });
                     $hasParamsByRef = !CArray::isEmpty($paramsByRef);
                 }
                 $method->stmts[0]->setAttribute("_imFirstStmtInMethodOrFunction", true);
                 $method->stmts[CMap::length($method->stmts) - 1]->setAttribute("_imLastStmtInMethodOrFunction", true);
                 $statements = [$method];
                 $methodFirstLastStmtVisitor = new CMethodOrFunctionFirstLastStmtVisitor($hasParams, $params, $hasParamsByRef, $paramsByRef);
                 $traverser = new PhpParser\NodeTraverser();
                 $traverser->addVisitor($methodFirstLastStmtVisitor);
                 $statements = $traverser->traverse($statements);
                 $method = $statements[0];
                 $returnVisitor = new CReturnVisitor($hasParams, $params, $hasParamsByRef, $paramsByRef, $method->byRef, CReturnVisitor::SUBJ_METHOD);
                 $traverser = new PhpParser\NodeTraverser();
                 $traverser->addVisitor($returnVisitor);
                 $statements = $traverser->traverse($statements);
                 return $statements;
             } else {
                 if ($node instanceof PhpParser\Node\Expr\Closure) {
                     $this->m_numEnteredClosures--;
                 } else {
                     if ($node instanceof PhpParser\Node\Stmt\Function_) {
                         $this->m_numEnteredFunctions--;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Returns all the values assigned to a specified long option with which the script was run,
  * e.g. "--option=value1 --option=value2".
  *
  * @param  string $optionName The name of the option, excluding "-".
  *
  * @return CArrayObject The values of the option specified, where each value is of type `CUStringObject`.
  */
 public static function valuesForLongOption($optionName)
 {
     assert('is_cstring($optionName)', vs(isset($this), get_defined_vars()));
     assert('self::hasLongOptionWithValue($optionName)', vs(isset($this), get_defined_vars()));
     $opt = getopt("", ["{$optionName}:"]);
     $values = $opt[$optionName];
     return oop_a(is_cmap($values) ? CArray::fromPArray($values) : CArray::fromElements($values));
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /**
  * Returns the names of the time zones that are known for a specified country.
  *
  * If the country's code is not recognized for any reason, the entire list of the known time zone names is
  * returned.
  *
  * @param  string $countryCode The two-letter code of the country, as provided by ISO 3166.
  *
  * @return CArrayObject The known time zone names for the country specified, of type `CUStringObject`.
  */
 public static function knownNamesForCountry($countryCode)
 {
     assert('is_cstring($countryCode)', vs(isset($this), get_defined_vars()));
     $paNames = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $countryCode);
     $paNames = CMap::filter($paNames, "CTimeZone::isNameIcuCompatible");
     $names = CArray::fromPArray($paNames);
     if (is_cmap($paNames) && !CArray::isEmpty($names)) {
         return oop_a($names);
     } else {
         return oop_a(self::knownNames());
     }
 }
Exemplo n.º 8
0
 /**
  * Extracts and returns the values from a map, as an array.
  *
  * @param  map $map The map to be looked into.
  *
  * @return CArray The map's values.
  */
 public static function values($map)
 {
     assert('is_cmap($map)', vs(isset($this), get_defined_vars()));
     return CArray::fromPArray($map);
 }
Exemplo n.º 9
0
/**
 * @ignore
 */
function _to_oop_tp($value)
{
    // Only used with OOP wrapping for third-party components.
    if (is_array($value)) {
        foreach ($value as &$mapValue) {
            $mapValue = _to_oop_tp($mapValue);
        }
        unset($mapValue);
        if (!CMap::areKeysSequential($value)) {
            $value = oop_m($value);
        } else {
            $value = oop_a(CArray::fromPArray($value));
        }
        return $value;
    }
    if ($value instanceof SplFixedArray) {
        $len = CArray::length($value);
        for ($i = 0; $i < $len; $i++) {
            $value[$i] = _to_oop_tp($value[$i]);
        }
        return oop_a($value);
    }
    return $value;
}
Exemplo n.º 10
0
 /**
  * Returns the paths to the subdirectories found by a wildcard pattern.
  *
  * Wildcard patterns use "\*" to match zero or more arbitrary characters, except the character of "/", and "?" to
  * match any single arbitrary character, again except the character of "/". For example, "\*.png" pattern searches
  * for all PNG images in the *current* directory, and "/path/to/any\*subdir/\*thumb-year-201?\*" searches for all
  * thumbnail images dated by the years of 2010-2019 and that are contained in the directories with a path matching
  * the rest of the pattern. Distinct from regular expressions, wildcard patterns need to be anchored at both ends,
  * so if the pattern in the last example was not concluded with "\*", no images would be found. Wildcards also
  * support character classes, such as "[abc]" and "[0-9]" as well as "[^abc]" and "[^0-9]", which however is only a
  * small portion of what regular expressions can do.
  *
  * To also search among the subdirectories that are contained in the subdirectories of the specified wildcard
  * pattern and so on, you can use `findDirectoriesRecursive` method.
  *
  * The returned paths are always absolute.
  *
  * @param  string $wildcardPattern The wildcard pattern to be used for searching.
  * @param  bool $sort **OPTIONAL. Default is** `false`. Tells whether the returned paths should be sorted, in the
  * ascending order.
  *
  * @return CArrayObject The paths to the subdirectories found by the wildcard pattern specified.
  *
  * @link   #method_findDirectoriesRecursive findDirectoriesRecursive
  */
 public static function findDirectories($wildcardPattern, $sort = false)
 {
     assert('is_cstring($wildcardPattern) && is_bool($sort)', vs(isset($this), get_defined_vars()));
     $wildcardPattern = CFilePath::frameworkPath($wildcardPattern);
     $paSearchRes = glob($wildcardPattern, GLOB_NOSORT | GLOB_ONLYDIR);
     assert('is_cmap($paSearchRes)', vs(isset($this), get_defined_vars()));
     $searchRes = CArray::fromPArray($paSearchRes);
     if ($sort) {
         CArray::sortUStringsNatCi($searchRes);
     }
     return oop_a($searchRes);
 }
Exemplo n.º 11
0
 /**
  * Converts a PHP's associative array or an OOP map into an OOP array.
  *
  * @param  map $map The PHP's associative array or the OOP map to be converted.
  *
  * @return CArrayObject The resulting array.
  */
 public static function fromPArray($map)
 {
     return self::fromSplArray(CArray::fromPArray($map));
 }
Exemplo n.º 12
0
 protected static function recurseQueryValueAfterParsing($value, $currDepth)
 {
     if ($currDepth == self::$ms_maxRecursionDepth) {
         return $value;
     }
     $currDepth++;
     if (!is_cmap($value)) {
         // Only interested in PHP's associative arrays.
         return $value;
     }
     if (CMap::areKeysSequential($value)) {
         $value = CArray::fromPArray($value);
         $len = CArray::length($value);
         for ($i = 0; $i < $len; $i++) {
             $value[$i] = self::recurseQueryValueAfterParsing($value[$i], $currDepth);
         }
         return oop_a($value);
     } else {
         foreach ($value as &$mapValue) {
             $mapValue = self::recurseQueryValueAfterParsing($mapValue, $currDepth);
         }
         unset($mapValue);
         return oop_m($value);
     }
 }
Exemplo n.º 13
0
 protected static function recurseValueAfterDecoding($value, $currDepth)
 {
     if ($currDepth == self::$ms_maxRecursionDepth) {
         return $value;
     }
     $currDepth++;
     if (is_string($value)) {
         return $value;
     }
     if (is_object($value)) {
         $value = (array) $value;
         foreach ($value as &$valueInMap) {
             $valueInMap = self::recurseValueAfterDecoding($valueInMap, $currDepth);
         }
         unset($valueInMap);
         $value = oop_m($value);
     } else {
         if (is_array($value)) {
             $value = CArray::fromPArray($value);
             $len = CArray::length($value);
             for ($i = 0; $i < $len; $i++) {
                 $value[$i] = self::recurseValueAfterDecoding($value[$i], $currDepth);
             }
             $value = oop_a($value);
         }
     }
     return $value;
 }