Composer - files autoload - does not work

Asked

Viewed 92 times

0

My code in Composer.json looks like this

{
    "name": "testesocial/vinicius",
    "description": "Login com facebook",
    "type": "project",
    "minimum-stability": "stable",
    "autoload": {
        "psr-4": {
            "Source\\": "testeoauth/"
        },
        "files": [
            "source/Config.php"
        ]
    },
    "require": {
        "league/oauth2-facebook": "^2.0.*"
    }
}

my source->config.php looks like this:

define("FACEBOOK", [
    "app_id" => "",
    "app_secret" => "",
    "app_redirect" => "https://www.localhost/testeoauth/",
    "app_version" => "v4.0"
]);

I’d like to leave this file with the FACEBOOK array on autolood, but it’s not getting, so I’m having to give require always, so:

<?php
ob_start();

require "vendor/autoload.php";
// require "source/Config.php";

if(empty($_SESSION["userLogin"])) {    
    echo "<h1>Guest</h1>";

    $facebook = new \League\OAuth2\Client\Provider\Facebook([
    'clientId'                => FACEBOOK["app_id"],
    'clientSecret'            => FACEBOOK["app_secret"],
    'redirectUri'             => FACEBOOK["app_redirect"],
    'graphApiVersion'         => FACEBOOK["app_version"]
]);

$authUrl = $facebook->getAuthorizationUrl([
    "scope" => ["email"]
]);

echo "<a title='FB Login' href='{$authUrl}'>Facebook Login</a>";

} else {
    echo "<h1>User Name</h1>";
}

ob_end_flush();

I wish I didn’t have to give the required

  • require "vendor/autoload.php"; if that line is spoken ???

  • No, the line that is commented to "require "source/Config.php" Without it my code breaks.

  • 1

    I need to know then the set of folders, if you have the github of it?

  • Got no, I got his zip.

  • it might work but, not the way you did, and another need to put in the packgist that there in the package manager

  • Here is the link to github: https://github.com/sahusa/testeoauth

  • 1

    Boy is the other link! if you’re half lost.

  • I sent you the link to my project’s github repository

  • 2

    In the Github repository you only have the Composer files and the index.php, missing the rest. Review the names of the files and folders, it may be a typo

  • But the project really only contains these files currently, I’m just testing the use of Composer, already managed to find the solution, grateful.

Show 5 more comments

1 answer

0

I was able to solve the personal problem. Just need to load autoload, for that it is necessary to execute the command 'Composer dumpautoload' and ready. I thank those who tried to help me in some way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.