Search code examples
phpzend-framework2

Class 'Geocoder\Provider\GoogleMapsProvider' not found


I'm trying to run some legacy application but I hit a wall with a geocoder dependency.

I get the message: Fatal error: Class Geocoder\Provider\GoogleMapsProvider' not found.

My source code shows the error at the marked line:

<?php

namespace Application\Geocoder\Provider;

use Geocoder\Exception\NoResultException;
use Geocoder\Exception\QuotaExceededException;
use Geocoder\Exception\UnsupportedException;
use Geocoder\Exception\InvalidCredentialsException;
use Geocoder\HttpAdapter\HttpAdapterInterface;
use Geocoder\Provider\GoogleMapsProvider as ExtendGoogleMapsProvider;

class GoogleMapsProvider extends ExtendGoogleMapsProvider
{ <===== The error line is HERE

I installed the willdurand/geocoder dependency:

  "require" : {
    "doctrine/doctrine-orm-module" : "0.7.0",
    "php" : ">=5.3.3",
    "gedmo/doctrine-extensions" : "2.3.8",
    "bjyoungblood/bjy-authorize" : "1.4.0",
    "doctrine/common" : "2.3.0",
    "twbs/bootstrap" : "2.3.2",
    "zf-commons/zfc-user" : "0.1.x-dev",
    "zf-commons/zfc-user-doctrine-orm" : "master-dev",
    "mwillbanks/zfc-twitter-bootstrap" : "master-dev",
    "zendframework/zendframework" : "2.2.5",
        "willdurand/geocoder": "^3.3",
    "firebase/php-jwt": "^4.0"
  },

And a diagnose command says:

$ php composer.phar diagnose
Checking composer.json: FAIL
name : invalid value (Extrapack), must match [A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]*
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
require.gedmo/doctrine-extensions : exact version constraints (2.3.8) should be avoided if the package follows semantic versioning
require.bjyoungblood/bjy-authorize : exact version constraints (1.4.0) should be avoided if the package follows semantic versioning
require.doctrine/common : exact version constraints (2.3.0) should be avoided if the package follows semantic versioning
require.twbs/bootstrap : exact version constraints (2.3.2) should be avoided if the package follows semantic versioning
require.zf-commons/zfc-user-doctrine-orm : unbound version constraints (master-dev) should be avoided
require.mwillbanks/zfc-twitter-bootstrap : unbound version constraints (master-dev) should be avoided
require.zendframework/zendframework : exact version constraints (2.2.5) should be avoided if the package follows semantic versioning
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK

My phar module:

Phar: PHP Archive support   enabled
Phar EXT version    2.0.2
Phar API version    1.1.1
SVN revision    $Id: 780be432570e80dd34c1a9c217ef87ade22bf136 $
Phar-based phar archives    enabled
Tar-based phar archives enabled
ZIP-based phar archives enabled
gzip compression    enabled
bzip2 compression   enabled
Native OpenSSL support  enabled

Onr thing that puzzles me in the source code, is the use of

use Geocoder\Provider\GoogleMapsProvider as ExtendGoogleMapsProvider;

which indicates the class extends itself. This makes no sense to me.


Solution

  • If you take a look at the source, the class Geocoder\Provider\GoogleMapsProvider does not exist.

    This may indicate that you are using a newer version than the legacy project used to.

    Looking at the changelog confirms that the Provider suffix has been removed in the 3.x line.

    For a start, you probably want to use an older version. Run

    $ composer require willdurand/geocoder:^2.8.2
    

    Alternatively, try using the renamed provider without the suffix on the 3.x line:

    use Geocoder\Provider\GoogleMaps;
    
    class GoogleMapsProvider extends GoogleMaps
    {
        // ...
    }
    

    Note The class name is aliased using

    use Geocoder\Provider\GoogleMapsProvider as ExtendGoogleMapsProvider;
    

    to prevent collisions.

    For reference, see: