Some severe classloading issue

ttrepper
Member | 11
+
0
-

Hi all, I am sorry if that's the wrong forum of if I have misunderstood something but I have a strange error and feel being stuck. I have started with this example: "":https://github.com/…ples/fifteen

Here is what I have:

folder structure is:

\
\index.php <- taken from doc. Entry point from webserver/browser
\app
\app\Bootstrap.php <- taken from doc
\vendor
\vendor\bin
\vendor\composer
\vendor\nette
\vendor\tracy

The content is for index.php (taken from here: "":https://github.com/…ww/index.php)

<?php

use App\Bootstrap;

require ('vendor/autoload.php');

App\Bootstrap::boot();	<----- here I get the Class "App\Bootstrap" not found exception

The content of Bootstrap.php (taken from here: "":https://github.com/…ootstrap.php)

namespace App;

use Nette\Bootstrap\Configurator;

class Bootstrap {

	public static function boot() : void {	//simplified

		echo ("TEST");

	}

}

Sorry for bothering – pretty sure it's a simple thing but I don't see it. Any help or pointing me to the right direction is highly appreciated please.

Thanks a lot in advance,
Thomas

nightfish
Member | 472
+
+1
-

Do you have autoload configuration in composer.json file? Such as can be seen here?

If yes, try running composer dump-autoload in your console/command line.

ttrepper
Member | 11
+
0
-

Thank you @nightfish. No – I have not but I can add it. 😃 My composer.json looks like this:

{
    "require": {
        "tracy/tracy": "^2.10",
        "nette/forms": "^3.1",
        "nette/database": "^3.1",
        "nette/bootstrap": "^3.2",
        "nette/mail": "^4.0",
        "nette/application": "^3.1"
    }
}

In the example

"autoload": {
		"psr-4": {
			"App\\": "app"
		}
	},

Do I have to use the exact same block? What does “psr-4” mean?

Thank you very much in advance,
Thomas

ttrepper
Member | 11
+
0
-

Found it: "":https://www.php-fig.org/psr/psr-4/

Thank you all 😃

nightfish
Member | 472
+
+1
-

@ttrepper PSR-4 is a specification for autoloading (i.e. discovering) classes in PHP.

psr-4 section in composer.json is a configuration, upon which a PSR-4 compliant autoloader is generated by Composer. (see composer docs and this for more information)

flowthentic
Member | 2
+
0
-

What I can see on your code that namespace App is not used…

Either use App and call your App\Bootstrap::boot()
With use App\Bootstrap call Bootstrap::boot()
Or you can rawly call \App\Bootstrap::boot() as well.