We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Using external OpenID library, and how to ensure include paths resolve correctly.

Hi, experienced developer, but phalcon newbie here. I'm building an OpenID auth system (log in with google/facebook/twitter etc) though this question is not specific to that scenario.

When I want to use an external library, for example Google's php-api-client library, I can't seem to work out how to successfully register this with my application.

I have used Phalcon\Loader to register my 'libraries' folder, but when I call a class that exists in that folder which relies upon other classes in sub folders, it cannot locate the files in the sub folders and complains about paths with a "failed to open stream: No such file or directory in..."

Am I missing something? Should I be registering all of the sub folders in 'libraries'? Am I going to have to edit all of the "require_once" statements in every google library file?

Hi,
You can use composer for autoloading class than Phalcon Loader if you want
In your bootstrap file

//$loader = new \Phalcon\Loader();
include __DIR__ . "/../app/vendor/autoload.php";

in your app/composer.json use https://packagist.org/packages/nyholm/google-api-php-client

{
    "require": {
        "php": ">=5.3.6",
        "phalcon/incubator": "1.3.0.*@dev",
        "nyholm/google-api-php-client": "dev-master"
    },
    "autoload": {
        "classmap": ["models/","controllers/","plugins/","forms/"],
        "files": ["library/lib.php"],
        "psr-0" : {
        }
    }
}

Did you work this out?

I noticed in the Git source tree that some of the files in the 'Google' folder were requiring files which were also linked to the 'Google' folder. If you were to run those files you would be requesting 'Google\Google...'. The 'Client.php' file is one example. I'm not sure if this happens when you clone it, but this is the way is appears on GitHub.

Have you tried interacting with the library outside of Phalcon? Does it work as expected? If so, please ignore these observations.

I am interested in how you go making this work as I, too, have a need to use that library.

edited Mar '14

I've actually just finished the implementation, I ended up using HybridAuth instead of Google's library. It offers OAuth functionality for numerous providers rather an just Google. I also ended up putting a set_include_path() in my bootstrap file which made loading the classes easier.



17.0k

Joearcher, is there some way I can contact you?

Can you not just post your question here?



17.0k
edited Jul '14

Sure, but your last post was on 14.03. so I thought you are rarely here :) I wanted to ask you if you could post your implementation of HybridAuth in Phalcon on Github? I'm having troubles implementing it. Could you please upload/post your controller, bootrstrap and hybridauth folder?

Possibly. It was implemented for a client so I will have to remove any project specific code. I will try to do this.



17.0k
edited Jul '14

Thanks . Means to me a lot since the only phalcon related topic about hybridauth is this one.

Also, you dont have to bother with a example that would work out of the box, login controller, bootrstrap and hybridauth config are enough :)