Sage10 warning & fatal errors on initial setup: Too few arguments to function App\\Composers\\Title

Hi all,

Took a spin with Sage10 and Zurb Foundation on PHP7.3. This is not a Trellis or Bedrock based system. After activating the theme when trying to visit the front page I get:

PHP Warning:  Declaration of App\\Composers\\Alert::with($data, $view) should be compatible with Roots\\Acorn\\View\\Composer::with() in theme/app/Composers/Alert.php on line 7
PHP Warning:  Declaration of App\\Composers\\Title::with($data, $view) should be compatible with Roots\\Acorn\\View\\Composer::with() in theme/app/Composers/Title.php on line 0
PHP Fatal error:  Method Illuminate\\View\\View::__toString() must not throw an exception, caught ErrorException: Too few arguments to function App\\Composers\\Title::with(), 0 passed in theme/vendor/roots/acorn/src/Acorn/View/Composer.php on line 53 and exactly 2 expected (View: theme/resources/views/index.blade.php) in theme/index.php on line 0

Also I would suggest adding that
theme/storage/framework/views/
theme/storage/framework/cache/
must be writeable by the server, to the documentation.

I tried running composer dump-autoload and that did not clear up the situation (saw it recommended a few places).

Also I was not sure the correct directory in which to run php artisan cache:clear or php artisan config:clear which I figured might clear the situation due to other recommendations

It’s possible I mixed up this installation and will try running the installer fresh again (my yarn was out of date when it ran initially). this was with the code on the 10.0.0-dev branch last night - had to call it a night before proceeding further. Best regards!

Ah I have a bit of a clue - although it’s challenging to understand all this.

sage/app/Composers/Alert.php and sage/app/Composers/Title.php are both extensions of the Roots\Acorn\View\Composer class.

The Composer abstract class at acorn/src/Acorn/View/Composer.php has
protected function with()
that has no parameters. It returns an array in the abstract class here.

Alert has this ‘with’ function with two parameters:

/**
* Data to be passed to view before rendering.
*
* @param array $data
* @param \Illuminate\View\View $view
* @return array
*/
public function with($data, $view)
{
return [
‘type’ => $data[‘type’] ?? ‘primary’,
];
}

Title also expects two parameters:

/**
* Data to be passed to view before rendering.
*
* @param array $data
* @param \Illuminate\View\View $view
* @return array
*/
public function with($data, $view)
{
return [‘title’ => $this->title($view->getName())];
}

Perhaps it would be best to re-engineer this so the with() function on the abstract class accepts an array that is allowed to be empty and then change Alert and Title to be accessing elements of that array. I’m not sure if that is the best choice but it would be more flexible I suppose.

(per here its recommended for parameters not to vary in number on abstract classes PHP: Can I declare an abstract function with a variable number of arguments? - Stack Overflow )

This is due to a recent Composer refactor in Acorn. I’ll see about pushing out an update to Sage 10 today.

Edit: This has been fixed.

Future documentation will show more in-depth examples on Composers as well as the available Caching and ACF traits.

This topic was automatically closed after 42 days. New replies are no longer allowed.