예제 #1
0
 private function loadDatas()
 {
     $datas = json_decode(file_get_contents($this->file), true);
     foreach ($datas as $regionCode => $regionDatas) {
         $region = new Region();
         $region->setCode($regionCode);
         $region->setName($regionDatas['name']);
         foreach ($regionDatas['depts'] as $deptCode => $deptDatas) {
             $departement = new Departement();
             $departement->setCode($deptCode);
             $departement->setName($deptDatas['name']);
             $departement->setRegion($region);
             $region->addDepartement($departement);
             if (!isset($deptDatas['cities'])) {
                 $deptDatas['cities'] = array();
             }
             // add cities
             foreach ($deptDatas['cities'] as $zipcode => $cities) {
                 $communes = new Sequence();
                 foreach ($cities as $cityName) {
                     $commune = new Commune($cityName, $zipcode, $departement);
                     $this->addToIndex('communes', $cityName, $zipcode);
                     $communes->add($commune);
                     $departement->addCommune($commune);
                 }
                 $this->communes->set($zipcode, $communes);
             }
             $this->addToIndex('departements', $deptDatas['name'], $deptCode);
             $this->departements->set($deptCode, $departement);
         }
         $this->addToIndex('regions', $region->getName(), $regionCode);
         $this->regions->set($regionCode, $region);
     }
 }
 /**
  * Adds a values
  *
  * @param  string $values
  * @return self
  */
 public function addValue($values)
 {
     if (!empty($values) && !$this->_values->contains($values)) {
         $this->_values->add($values);
     }
     return $this;
 }
예제 #3
0
 /**
  * Get all addresses for a query from the API.
  */
 public function search($query, $limit = null, $page = null)
 {
     $params = ['query' => $query];
     if (isset($limit)) {
         $params['limit'] = $limit;
     }
     if (isset($page)) {
         $params['page'] = $page;
     }
     $url = $this->getSearchUri($params);
     $response = $this->transport->get($url);
     $addresses = $this->parseResponse($response);
     $address_collection = new Sequence();
     if (isset($addresses['total'])) {
         $this->total = $addresses['total'];
     }
     if (isset($addresses['limit'])) {
         $this->limit = $addresses['limit'];
     }
     if (isset($addresses['page'])) {
         $this->page = $addresses['page'];
     }
     if (!empty($addresses['hits'])) {
         foreach ($addresses['hits'] as $address) {
             $address_collection->add(new Address($this->transport, $address));
         }
     }
     // Return a collection of addresses.
     return $address_collection;
 }
예제 #4
0
 function it_should_check_that_an_url_is_indexable_event_with_a_disallow_directive()
 {
     $url = "/bar/foo";
     $directives = new Sequence();
     $directives->add(new Directive('Disallow', '/bar'));
     $directives->add(new Directive('Allow', '/bar/foo'));
     $this->beConstructedWith('GoolgeBot', $directives);
     $this->isUrlAllowed($url)->shouldReturn(true);
 }
 /**
  * Sets attribute sequence
  *
  * @param  array $attrs
  * @return self
  */
 public function setAttrs(array $attrs)
 {
     $this->_attrs = new Sequence();
     foreach ($attrs as $attr) {
         $attr = trim($attr);
         if (!$this->_attrs->contains($attr)) {
             $this->_attrs->add($attr);
         }
     }
     return $this;
 }
예제 #6
0
 /**
  * Sets method sequence
  *
  * @param  array $methods
  * @return self
  */
 public function setMethods(array $methods)
 {
     $this->_methods = new Sequence();
     foreach ($methods as $value) {
         $value = trim($value);
         if (!$this->_methods->contains($value)) {
             $this->_methods->add($value);
         }
     }
     return $this;
 }
예제 #7
0
 /**
  * Get all addresses for a postcode from the API.
  */
 public function getAddresses($postcode)
 {
     $url = $this->getUri($postcode);
     $response = $this->transport->get($url);
     $addresses = $this->parseResponse($response);
     $address_collection = new Sequence();
     if (!empty($addresses)) {
         foreach ($addresses as $address) {
             $address_collection->add(new Address($this->transport, $address));
         }
     }
     // Return a collection of addresses.
     return $address_collection;
 }
예제 #8
0
 /**
  * Sets right sequence
  *
  * @param  array $rights
  * @return self
  */
 public function setRights(array $rights)
 {
     $this->_rights = new Sequence();
     foreach ($rights as $right) {
         $right = trim($right);
         if (!empty($right)) {
             $this->_rights->add($right);
         }
     }
     if (count($this->_rights) === 0) {
         throw new \InvalidArgumentException('DiscoverRights must have at least one right');
     }
     return $this;
 }
 /**
  * Sets token sequence
  *
  * @param  array  $tokens Tokens
  * @return self
  */
 public function setTokens(array $tokens)
 {
     $this->_tokens = new Sequence();
     foreach ($tokens as $token) {
         $token = trim($token);
         if (!empty($token) && !$this->_tokens->contains($token)) {
             $this->_tokens->add($token);
         }
     }
     if (count($this->_tokens) === 0) {
         throw new \InvalidArgumentException('RefreshRegisteredAuthTokens must have at least one token');
     }
     return $this;
 }
 public function add($serializer)
 {
     if (!$serializer instanceof BaseSerializer) {
         throw new \RuntimeException("Only search paramater objects allowed here.");
     }
     return parent::add($serializer);
 }
 public function add($resource)
 {
     if (!$resource instanceof LeadFerret\Lib\JSONSchema\Resource) {
         throw new Exceptions\InvalidParameterException("Only search paramater objects allowed here.");
     }
     return parent::add($resource);
 }
 /**
  *
  * @param Resource $resource            
  * @throws \RuntimeException
  */
 public function add($resource)
 {
     if (!$resource instanceof Resource) {
         throw new \RuntimeException("Only Resource objects allowed here.");
     }
     return parent::add($resource);
 }
 /**
  * Add a member
  *
  * @param  string $member
  * @return self
  */
 public function addMember($member)
 {
     $member = trim($member);
     if (!empty($member)) {
         $this->_members->add($member);
     }
     return $this;
 }
예제 #14
0
 /**
  * Appends an element at the end of the sequence.
  * @param T $element
  * @return self
  */
 public function add($element)
 {
     if ($element instanceof $this->_type) {
         parent::add($element);
     } else {
         throw new \UnexpectedValueException("TypedSequence<{$this->_type}> can only hold objects of {$this->_type} class.");
     }
     return $this;
 }
예제 #15
0
 /**
  * Set right sequence
  *
  * @param  array $rights
  * @return self
  */
 public function setRights(array $rights)
 {
     $this->_rights = new Sequence();
     foreach ($rights as $value) {
         $value = trim($value);
         if (!$this->_rights->contains($value)) {
             $this->_rights->add($value);
         }
     }
     return $this;
 }
 /**
  * Sets account sequence
  *
  * @param  array  $accounts Account
  * @return self
  */
 public function setAccounts(array $accounts)
 {
     $this->_accounts = new Sequence($accounts);
     foreach ($accounts as $dlm) {
         $dlm = trim($dlm);
         if (!empty($dlm) && !$this->_accounts->contains($dlm)) {
             $this->_accounts->add($dlm);
         }
     }
     return $this;
 }
 /**
  * Sets rights
  *
  * @param  string $rights
  * @return self
  */
 public function setRights(array $rights)
 {
     $this->_rights = new Sequence();
     foreach ($rights as $right) {
         $right = trim($right);
         if (!empty($right)) {
             $this->_rights->add($right);
         }
     }
     return $this;
 }
 /**
  * Sets member sequence
  *
  * @param  array  $members Members
  * @return self
  */
 public function setMembers(array $members)
 {
     $this->_members = new Sequence($members);
     foreach ($members as $dlm) {
         $dlm = trim($dlm);
         if (!empty($dlm) && !$this->_members->contains($dlm)) {
             $this->_members->add($dlm);
         }
     }
     if (!count($this->_members)) {
         throw new \InvalidArgumentException('RemoveDistributionListMember must have at least a member');
     }
 }
예제 #19
0
 /**
  * Get postcodes for a geographic location from the API.
  * The radius ranges up to 1000m, and defaults to 100m.
  * The limit ranges up to 150, defauling to 100.
  *
  * @param longitude decimal The location WGS84 longitude.
  * @param latitude decimal The location WGS84 latitude.
  * @param radius integer The radius in metres (up to 1000, default 100).
  * @param limit integer The radius in metres (up to 150, default 100).
  */
 public function getPostcodes($longitude, $latitude, $radius = null, $limit = null)
 {
     $lonlat = $longitude . ',' . $latitude;
     $params = ['lonlat' => $lonlat];
     if (isset($radius)) {
         $params['radius'] = $radius;
     }
     if (isset($limit)) {
         $params['limit'] = $limit;
     }
     $url = $this->getUri($params);
     $response = $this->transport->get($url);
     $postcodes = $this->parseResponse($response);
     $postcode_collection = new Sequence();
     if (!empty($postcodes)) {
         foreach ($postcodes as $postcode) {
             $postcode_collection->add(new Postcode($this->transport, $postcode));
         }
     }
     // Return a collection of postcodes.
     return $postcode_collection;
 }
 /**
  * Sets member sequence
  *
  * @param  array  $members Members
  * @return self
  */
 public function setMembers(array $members)
 {
     $this->_members = new Sequence();
     foreach ($members as $member) {
         $member = trim($member);
         if (!empty($member) && !$this->_members->contains($member)) {
             $this->_members->add($member);
         }
     }
     if (count($this->_members) === 0) {
         throw new \InvalidArgumentException('AddDistributionListMember must have at least one member');
     }
     return $this;
 }
예제 #21
0
 protected function setUp()
 {
     $this->seq = new Sequence();
     $this->seq->addAll(array(0, $this->a = new \stdClass(), $this->b = new \stdClass(), 0));
 }
예제 #22
0
 public function serializeSequence(VisitorInterface $visitor, Sequence $sequence, Type $type, Context $context)
 {
     return $visitor->visitArray($sequence->all(), $type, $context);
 }
예제 #23
0
 public function testIsEmpty()
 {
     $this->assertFalse($this->seq->isEmpty());
     $seq = new Sequence();
     $this->assertTrue($seq->isEmpty());
 }
예제 #24
0
 /**
  * Add a right
  *
  * @param  string $right
  * @return self
  */
 public function addRight($right)
 {
     $this->_right->add(trim($right));
     return $this;
 }
예제 #25
0
 /**
  * @param Checker $checker
  */
 public function addChecker(Checker $checker)
 {
     $this->checkers->add($checker);
     $this->checkers->sortWith($this->checkersSorter());
 }
 public function get($index)
 {
     $this->initialize($index);
     return parent::get($index);
 }
 /**
  * PHP Constructor
  *
  * @param array $elements
  */
 public function __construct(array $elements = array())
 {
     parent::__construct($elements);
     $this->post_type_labels = $this->get_post_type_labels();
     $this->post_type_args = $this->get_post_type_args();
 }
예제 #28
0
 /**
  * Add a method
  *
  * @param  string $method
  * @return self
  */
 public function addMethod($method)
 {
     $this->_method->add($method);
     return $this;
 }
예제 #29
0
 /**
  * Add an file
  *
  * @param  string $file
  * @return self
  */
 public function addFile($file)
 {
     $this->_files->add($file);
     return $this;
 }
 public function serializeSequence(VisitorInterface $visitor, Sequence $sequence, array $type, Context $context)
 {
     // We change the base type, and pass through possible parameters.
     $type['name'] = 'array';
     return $visitor->visitArray($sequence->all(), $type, $context);
 }