Exemplo n.º 1
0
 /**
  * Test "merge with all"
  *
  * @return void
  */
 public function testMergeWithAll()
 {
     $bag1 = new ParamBag(['a' => 1]);
     $bag2 = new ParamBag(['b' => 2]);
     $bag3 = new ParamBag(['c' => 3]);
     $bag3->mergeWithAll([$bag1, $bag2]);
     $this->assertEquals(['a' => [1], 'b' => [2], 'c' => [3]], $bag3->getArrayCopy());
 }
Exemplo n.º 2
0
 /**
  * Apply query defaults, appends, invariants.
  *
  * @param ParamBag $params     Parameters
  * @param array    $defaults   Query defaults
  * @param array    $appends    Query appends
  * @param array    $invariants Query invariants
  *
  * @return void
  */
 protected function apply(ParamBag $params, array $defaults, array $appends, array $invariants)
 {
     $final = $params->getArrayCopy();
     $final = array_replace($defaults, $final);
     $final = array_merge_recursive($final, $appends);
     $final = array_replace($final, $invariants);
     $params->exchangeArray($final);
 }
Exemplo n.º 3
0
 /**
  * Execute a search.
  *
  * @param ParamBag $params Parameters
  * @param integer  $offset Search offset
  * @param integer  $limit  Search limit
  *
  * @return string
  */
 public function search(ParamBag $params, $offset, $limit)
 {
     $params->set('startRecord', $offset);
     $params->set('maximumRecords', $limit);
     $params->set('servicelevel', 'full');
     $params->set('wskey', $this->wskey);
     $response = $this->call('POST', $params->getArrayCopy(), false);
     $xml = simplexml_load_string($response);
     $docs = isset($xml->records->record) ? $xml->records->record : [];
     $finalDocs = [];
     foreach ($docs as $doc) {
         $finalDocs[] = $doc->recordData->asXML();
     }
     return ['docs' => $finalDocs, 'offset' => $offset, 'total' => isset($xml->numberOfRecords) ? (int) $xml->numberOfRecords : 0];
 }
Exemplo n.º 4
0
 /**
  * Execute a search.
  *
  * @param ParamBag $params Parameters
  * @param int      $offset Search offset
  * @param int      $limit  Search limit
  *
  * @return array
  */
 public function search(ParamBag $params, $offset, $limit)
 {
     $startrec = $offset + 1;
     $params->set('startrec', $startrec);
     $params->set('numrec', $limit);
     $params->set('prof', $this->prof);
     $params->set('pwd', $this->pwd);
     $response = $this->call('GET', $params->getArrayCopy(), false);
     $xml = simplexml_load_string($response);
     $finalDocs = [];
     foreach ($xml->SearchResults->records->rec as $doc) {
         $finalDocs[] = simplexml_load_string($doc->asXML());
     }
     return ['docs' => $finalDocs, 'offset' => $offset, 'total' => (int) $xml->Hits];
 }