Saturday, April 1, 2017

Class not found - composer psr-4

So I have made my own library, the directory structure is:

src/
    Parser.php

composer.json

and my composer.json is

{
    "name": "my-user/aspect-parser",
    "version": "1.0.0",
    "type": "library",
    "require": {
        "nesbot/carbon": "^1.22"
    },
    "autoload": {
      "psr-4": {
        "AspectParser\\": "src/"
      }
    }
}

It is being added to the autoload_psr4.php:

'AspectParser\\' => array($vendorDir . '/my-user/aspect-parser/src')

But when I try and initiate the parser object, it says that the class is not found. My Parser.php file is:

namespace my-user\AspectParser;
use Carbon\Carbon;
Class Parser {
    public function parse()
    {
    }
}

And I'm trying to initiate it like such:

use AspectParser;
$parser = new AspectParser\Parser();

and I receive: Class 'AspectParser\Parser' not found



via Nathan

Advertisement