2

I created a package in the Laravel 4 workbench and it worked like a charm on my machine. Everything loaded as expected but now on another machine I'm getting the Class not found exception.

What I have:

composer.json (root)

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "workbench"
    ],
    "files": [
        "app/helpers.php"
    ]
},

Please note that the workbench directory is listed.

Inside the workbench directory I have the vendor and package folders: workbench/krynble/contenter

Inside is the regular package structure but the most important is that there is another composer.json file (created when the package was generated):

"autoload": {
    "classmap": [
        "src/migrations"
    ],
    "psr-0": {
        "Krynble\\Contenter\\": "src/"
    }
},

So inside of it I followed the steps to create the Service Provider cited in the documentation

workbench/krynble/contenter/src/Krynble/Contenter/ContenterSerivceProvider.php (also generated automaticaly) and left it as created, with only the boot method as follows:

public function boot()
{
    $this->package('krynble/contenter');
}

register:

public function register()
{
    //
}

provides:

public function provides()
{
    return array();
}

Added this service provider to my app.php in the providers list and invoking a die() in the boot function shows it's being called.

Last, I created my utility class:

workbench/krynble/contenter/src/Krynble/Contenter/Services/Mappers/MediaMapperSerivce.php

<?

namespace Krynble\Contenter\Services\Mappers;
class MediaMapperService {
...
}

Finally, in my controller:

<?php

use Krynble\Contenter\Services\Mappers\MediaMapperService;

class MediaController extends BaseController {

    private $mediaMapperService;


    public function __construct(MediaMapperService $mediaMapperService)
    {
        $this->mediaMapperService = $mediaMapperService;
    }

Nice! It worked on my machine (vagrant box with ubuntu)! But on the mac notebook it's not working (so I discarded the case-sensitive thing).

Any clues? Any way to debug? I'm going nuts, thrown die() in every point and can't seem to find the source.

Am I supposed to add something in the provides method in my service provider? If so, why did it work on my machine without adding this?

2
  • 2
    Does composer dump-autoload help? Commented Jul 26, 2014 at 17:09
  • Unfortunately, it did not. It runs and shows me Running for workbench [krynble/contenter]... but nothing changes =/ Commented Aug 1, 2014 at 4:48

1 Answer 1

3

After a log of digging, I found out the problem was the weirdest of all: the short_open_tag setting in local computer was set to 1 and was set to 0 in my QA environment.

The file wasn't being parsed (but no error raised) and I was getting the class does not exist message.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.