Search code examples
phpcomposer-phppsr-4

Composer not composing - saying file not found


I'm using the excellent phpwkhtmltopdf library and want to update to latest version and for this I need to use composer.

File structure:

vendor
  --mikehaertl
    --php-shellcommand
    --php-tmpfile
  autoload.php

Composer.json file:

{
"name": "mikehaertl/phpwkhtmltopdf",
"description": "A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface",
"keywords": ["pdf", "wkhtmltopdf", "wkhtmltoimage" ],
"homepage": "http://mikehaertl.github.com/phpwkhtmltopdf/",
"type": "library",
"license": "MIT",
"authors": [
    {
        "name": "Michael Haertl",
        "email": "[email protected]"
    }
],
"require": {
    "php": ">=5.0.0",
    "mikehaertl/php-tmpfile": "1.0.*",
    "mikehaertl/php-shellcommand": "1.0.*"
},
"autoload": {
    "psr-4": {
        "mikehaertl\\wkhtmlto\\": "src/"
    }
},
"extra": {
    "branch-alias": {
        "dev-master": "2.0.x-dev"
    }
}
}

I'm trying to use the library like this:

require '/home/bookmark/vendor/autoload.php';
use mikehaertl\wkhtmlto\Pdf;
...
$pdf = new Pdf('http://anysite.com'); <-- error points to this line

The problem is I get the error:

Fatal error: Class 'mikehaertl\wkhtmlto\Pdf' not found in /home/bookmark/public_html/ajax/action.php on line 132

This is my first time using composer, any idea what I'm doing wrong?


Solution

  • If you are using some package, you must not copy their composer.json file - that won't work.

    The best thing would be to run composer init once to create an initial composer.json file for your project, and composer require mikehaertl/phpwkhtmltopdf:~2.0 to add this package you want to work with.

    After that, it should work.