Geocoder\Provider\Chain::geocode PHP Method

geocode() public method

{@inheritDoc}
public geocode ( $address )
    public function geocode($address)
    {
        $exceptions = [];
        foreach ($this->providers as $provider) {
            if ($provider instanceof LocaleAwareProvider && $this->getLocale() !== null) {
                $provider = clone $provider;
                $provider->setLocale($this->getLocale());
            }
            try {
                return $provider->geocode($address);
            } catch (InvalidCredentials $e) {
                throw $e;
            } catch (\Exception $e) {
                $exceptions[] = $e;
            }
        }
        throw new ChainNoResult(sprintf('No provider could geocode address: "%s".', $address), $exceptions);
    }

Usage Example

Esempio n. 1
0
 public function testGeocodeThrowsChainNoResult()
 {
     $mockOne = $this->getMock('Geocoder\\Provider\\Provider');
     $mockOne->expects($this->exactly(2))->method('geocode')->will($this->returnCallback(function () {
         throw new \Exception();
     }));
     $chain = new Chain(array($mockOne, $mockOne));
     try {
         $chain->geocode('Paris');
     } catch (ChainNoResult $e) {
         $this->assertCount(2, $e->getExceptions());
     }
 }
All Usage Examples Of Geocoder\Provider\Chain::geocode