php - Class not found (composer.json)

340
December 19, 2016, at 10:05 PM

I'm trying to implement a PHP Library for detecting CMS I found on github, but I can't for the life of me figure it out.

I am new to php and composer, but I installed composer in my directory, then updated the json as instructed, but it cannot find the classes, despite them all being in the directory.

running this code

include(__DIR__ . "/vendor/autoload.php");
$domain = "http://google.com";
$cms = new DetectCMS($domain);
if($cms->getResult()) {
    echo "Detected CMS: ".$cms->getResult();
} else {
    echo "CMS couldn't be detected";
}

gives me this error

PHP Fatal error:  Uncaught Error: Class 'DetectCMS' not found in D:\Projects\Scraper\ccc.php:12
Stack trace:
#0 {main}
  thrown in D:\Projects\Scraper\ccc.php on line 12

here is my file structure:

would anyone have any idea what I'm doing wrong with this information? Thanks in advance

Answer 1

I think to include a class using the autoloader,in your class, you must do something about it:

in your composer.json

"autoload": {
    "psr-4" :{"DetectCMS": "DetectCMS"}
}

after in your class DetectCMS.php:

<?php
   use DetectCMS\DetectCMS;

or

<?php
$loader = require 'vendor/autoload.php';
$loader->add('DetectCMS', __DIR__.'DetectCMS');
Rent Charter Buses Company
READ ALSO
set ip based restriction on hosted openstreetmap nominatim service

set ip based restriction on hosted openstreetmap nominatim service

I have installed openstreetmap nominatim planet file in my server

259
mysqli_num_rows does not work after giving parameters [duplicate]

mysqli_num_rows does not work after giving parameters [duplicate]

This question already has an answer here:

328
PHP - Why do you need &#39;x&#39; permissions on a directory to read file stats?

PHP - Why do you need 'x' permissions on a directory to read file stats?

I'm trying to work out why I need x permissions for others on a directory to read the stats of the files within it

336
php ,openssl function generate random encoding , how can i correctly save encrypted text in database

php ,openssl function generate random encoding , how can i correctly save encrypted text in database

Kindly I am a developer with basics of encryption , I have a task which is encrypting data then save the encryption to database, I am using openssl php function to encrypte and decrypte like below

383