Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Class 'Login' not found #15

Closed
TheZoker opened this issue Sep 15, 2015 · 20 comments
Closed

Fatal error: Class 'Login' not found #15

TheZoker opened this issue Sep 15, 2015 · 20 comments

Comments

@TheZoker
Copy link

Awesome framework!

But I have a issue:
When I try to use Login::getToken() I get the error

Fatal error: Class 'Login' not found in /helper.php on line 42

But I included the class in the helper.php file:

<?php
require_once( 'framework/github-api.php' );
use Milo\Github;
@JanTvrdik
Copy link

You need to use namespace, i.e. Milo\Github\OAuth\Login.

@TheZoker
Copy link
Author

Ah ok works :) Thank you!
I now get something like this on var_dump:
img_2015 09 15_20h45m12s_005_

And when i simple return the token, I don`t get any output.

How can I get the token out of this?

@JanTvrdik
Copy link

You need to load github-api.php (or setup autoloading) before calling session_start.

@TheZoker
Copy link
Author

Yep I`m doing that, otherwise I would not get this response I guess.

@JanTvrdik
Copy link

No, __PHP_Incomplete_Class means that at the time of session_start the class Milo\Github\OAuth\Token is undefined.

@TheZoker
Copy link
Author

img_2015 09 15_20h55m37s_006_
This is my code
Without the github-api.php I would not be able to use Milo\Github\OAuth\ and these stuff, right?

@JanTvrdik
Copy link

Strange. Do you have error_reporting set to E_ALL and enabled display_errors?

@milo
Copy link
Owner

milo commented Sep 15, 2015

@TheZoker Try to dump the $_SESSION content. Isn't there some garbage? If so, clean it somehow.

The library uses $_SESSION['milo.github-api']. Isn't touched by another app?

@TheZoker
Copy link
Author

This is the dump of $_SESSION
img_2015 09 15_21h14m30s_008_
I use it to build a wordpress plugin, so it should be untouched

@milo
Copy link
Owner

milo commented Sep 15, 2015

Try unset($_SESSION['milo.github-api']) directly after the session_start(). Only once and remove it. Then, try whole auth roundtrip again.

@milo
Copy link
Owner

milo commented Sep 15, 2015

Oh, maybe I got it. Isn't session started somewhere earlier? I mean, your session_start() in oauth() function is the second call.

@TheZoker
Copy link
Author

But I dont have any other session_start() anywhere else

@milo
Copy link
Owner

milo commented Sep 15, 2015

Wordpress does not start it? Or maybe PHP's session.auto_start? Try var_dump(session_status()); before the require_once ...;

@TheZoker
Copy link
Author

img_2015 09 15_21h38m20s_009_
So there is another plugin uses the session

Btw: How can I open the oauth window in a new window (popup)?

@milo
Copy link
Owner

milo commented Sep 15, 2015

I see. So, session is somewhere already started before you load the github-api libs. I don't know the Wordpress, maybe there is some hook for plugins to load the libraries first.

If not, you can try this nasty hack in here and let me know.

public function getToken()
{
    $token = $this->storage->get('auth.token');
    if ($token === NULL) {
        throw new Github\LogicException('Token has not been obtained yet.');
    } elseif ($token instanceof \__PHP_Incomplete_Class) {
        $token = unserialize(serialize($token));
    } 
    return $token;
}

@milo
Copy link
Owner

milo commented Sep 15, 2015

Btw: How can I open the oauth window in a new window (popup)?

Sorry, that's the frontend thing which I don't solve.

@TheZoker
Copy link
Author

milo added a commit that referenced this issue Sep 16, 2015
When stored as a Token object, can be unserialized as an __PHP_Incomplete_Class when session starts before the library is loaded.
@milo
Copy link
Owner

milo commented Sep 16, 2015

@TheZoker The error is caused by the Same Origin Policy setting. It is not relevant to this library.

Anyway, I released a new version 1.4.3 where is a token in session stored as an ordinary array. It prevents __PHP_Incomplete_Class error.

@TheZoker
Copy link
Author

@milo Is there any way to generate and save a state without calling askPermissions() ?

@milo
Copy link
Owner

milo commented Sep 17, 2015

No, if you need a user's permissions. Btw. why do you access GitHub webpage by AJAX? You need to redirect a browser window. User will click 'Accept' on GitHub web and than will be redirected back to your site.

@milo milo closed this as completed Oct 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants