Example #1
0
 /**
  * Set url query param.
  *
  * @param StringObject|ArrayObject|string|array $query  Query params.
  * @param bool                                  $append Do you want to append or overwrite current query param.
  *                                                      In case when you are appending values, the values from $query,
  *                                                      that already exist in the current query, will be overwritten
  *                                                      by the ones inside the $query.
  *
  * @throws UrlObjectException
  * @return $this
  */
 public function setQuery($query, $append = false)
 {
     if ($this->isStdObject($query)) {
         $query = $query->val();
     }
     if ($append && $this->query != '') {
         if ($this->isString($this->query)) {
             $currentQuery = new StringObject($this->query);
             $currentQuery = $currentQuery->parseString();
         } else {
             $currentQuery = new ArrayObject($this->query);
         }
         if ($this->isStdObject($query)) {
             if (StdObjectWrapper::isArrayObject($append)) {
                 $query = $query->val();
             } else {
                 if (StdObjectWrapper::isStringObject($query)) {
                     $query = $query->parseString()->val();
                 } else {
                     throw new UrlObjectException(UrlObjectException::MSG_INVALID_ARG, ['$query', 'StringObject|ArrayObject|string|array']);
                 }
             }
         } else {
             if ($this->isString($query)) {
                 $query = new StringObject($query);
                 $query = $query->parseString()->val();
             }
         }
         $currentQuery->merge($query);
         $query = $currentQuery->val();
     }
     $this->query = $query;
     $this->rebuildUrl();
     return $this;
 }
Example #2
0
 /**
  * Extend $config with $parentConfig
  *
  * @param ArrayObject $config       Child config object
  * @param ArrayObject $parentConfig Parent config object
  *
  * @return ArrayObject
  */
 private function extendConfig(ArrayObject $config, ArrayObject $parentConfig)
 {
     $configCalls = null;
     $overrideCalls = false;
     // Get calls arrays
     if ($config->keyExists('Calls')) {
         $configCalls = $config->key('Calls');
     } elseif ($config->keyExists('!Calls')) {
         $configCalls = $config->key('!Calls');
         $overrideCalls = true;
     }
     $parentCalls = $parentConfig->key('Calls', [], true);
     // Merge basic values
     $config = $parentConfig->merge($config);
     // Remove unnecessary keys
     $config->removeKey('Parent')->removeKey('Abstract')->removeKey('Calls');
     // Merge calls
     if (!$this->isNull($configCalls) && !$this->isNull($parentCalls)) {
         if ($overrideCalls) {
             $config->key('!Calls', $configCalls);
             return;
         }
         foreach ($configCalls as $call) {
             $call = $this->arr($call);
             if ($call->keyExists(2)) {
                 $parentCalls[$call[2]] = $call->val();
             } else {
                 $parentCalls[] = $call->val();
             }
         }
         $config->key('Calls', $parentCalls);
     } elseif ($this->isNull($configCalls) && !$this->isNull($parentCalls)) {
         $config->key('Calls', $parentCalls);
     } elseif (!$this->isNull($configCalls) && $this->isNull($parentCalls)) {
         $config->key('Calls', $configCalls);
     }
     return $config;
 }
Example #3
0
 /**
  * @dataProvider arraySet1
  */
 public function testMerge($array)
 {
     $a = new ArrayObject($array);
     $a->merge($array);
     $array = array_merge($array, $array);
     $this->assertSame($array, $a->val());
 }