Home » Php » php – RoboFile composer autoload trait not found

php – RoboFile composer autoload trait not found

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m trying to use a Parameter file writer package in my RoboFile, loading it via composer.

RoboClass:

<?php
use Symfony\Component\Finder\Finder;
use Robo\Result;
use Robo\Collection\CollectionBuilder;
use Nordcode\RoboParameters\loadTasks;

  class RoboFile extends \Robo\Tasks
  {
    use loadTasks;

    public function sometask()
    {
       //something
    }

when trying to call sometask()
I get the following error:

PHP Fatal error: Trait 'Nordcode\RoboParameters\loadTasks' not found in /projects/Robo/RoboFile.php on line 9

while I can find it in composers autoload_classmap.php

'NordCode\RoboParameters\loadTasks' => $vendorDir . '/nordcode/robo-parameters/src/loadTasks.php',

Am I missing something?

Edit 12.02.16:
Fixed “\” in at the beginning of the namespace, doesn’t seem to make a difference

Also fixed lower case trait name 🙂

The contents of what appears to be the bootstrap.php

<?php

if (strpos(basename(__FILE__), 'phar')) {
    require_once 'phar://robo.phar/vendor/autoload.php';
} else {
    if (file_exists(__DIR__.'/vendor/autoload.php')) {
        require_once __DIR__.'/vendor/autoload.php';
    } elseif (file_exists(__DIR__.'/../../autoload.php')) {
        require_once __DIR__ . '/../../autoload.php';
    } else {
        require_once 'phar://robo.phar/vendor/autoload.php';
    }
}
$runner = new \Robo\Runner();
$statusCode = $runner->execute($_SERVER['argv']);
exit($statusCode);

contents of LoadTasks

<?php

namespace NordCode\RoboParameters;

use NordCode\RoboParameters\Task\Parameters;
use NordCode\RoboParameters\Task\SymfonyParameters;

trait LoadTasks
{
   //functions
}
How to&Answers:

I am working with Tobias and it worked for me now…
I did not exactly change anything. Just re-setup it on my machine.