Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Followed instructions, but also get "Call to undefined function app()" #17

Closed
farmerpaul opened this issue Nov 27, 2018 · 9 comments
Closed

Comments

@farmerpaul
Copy link

Similarly to the authors of #9 and #3, I too am getting Call to undefined function app() when I try to install your library and call @svg('some-svg') in my code. Here's the full message:

Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined function app() in /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/nothingworks/blade-svg/src/helpers.php:15
Stack trace:
#0 /srv/www/bgr/htdocs/wp-content/uploads/cache/f55cf797dc38eb655f771426241b544eed5f52f2.php(9): svg_image('logo')
#1 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/Engines/PhpEngine.php(43): include('/srv/www/bgr/ht...')
#2 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/srv/www/bgr/ht...', Array)
#3 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/srv/www/bgr/ht...', Array)
#4 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents()
#5 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/View.php(90): Illuminate\View\View->renderContents()
#6 /srv in /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/nothingworks/blade-svg/src/helpers.php on line 15

I have PHP 7.2, Sage 9.0.5, and Composer 1.7.3. As instructed, I ran composer require log1x/blade-svg-sage, and it installed version 0.3.0 of nothingworks/blade-svg and 2.0.0 of log2x/blade-svg-sage:

$ composer require log1x/blade-svg-sage
Using version ^2.0 for log1x/blade-svg-sage
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing nothingworks/blade-svg (v0.3.0): Downloading (100%)         
  - Installing log1x/blade-svg-sage (v2.0.0): Downloading (100%)         
Writing lock file
Generating autoload files

I've even installed the blade-generate WP-CLI tool to make sure the Blade cache was clear and tried recompiling, but it insists on generating code that tries to call the undefined function app().

Any idea what I've done wrong?

@farmerpaul
Copy link
Author

Well, I have no clue how Composer's loader is supposed to work, but for whatever reason, when I install your package following your own instructions, the app prefers the svg_image() function defined in nothingworks/blade-svg/src/helpers.php instead of your own log1x/blade-svg-sage/src/helpers.php. Since I'm clueless for how to get Composer to give your function priority instead, my clumsy workaround was to edit nothingworks/blade-svg/src/helpers.php and essentially replace the function body of svg_image() with your version, making a few tweaks:

if (! function_exists('svg_image')) {
    function svg_image($name, $class = '', $attrs = [])
    {
        if (empty($name)) {
            return;
        }

        // Add `App\` and `BladeSvgSage\` below to reference the other namespaces properly.
        return App\sage(BladeSvgSage\BladeSvgSage::class)->svg($name, $class, $attrs);
    }
}

…

Hopefully this helps someone else who's trying to get this package to work.

@Log1x
Copy link
Owner

Log1x commented Nov 28, 2018

Working on a fix for this now. For some reason, I didn't run into this issue during initial testing prior to release.

@Log1x
Copy link
Owner

Log1x commented Nov 28, 2018

Should be fixed now in the v2.0.1 release.

@Log1x Log1x closed this as completed Nov 28, 2018
@farmerpaul
Copy link
Author

Thanks for your quick response, however I'm afraid this hasn't fixed the issue for me:

$ composer remove log1x/blade-svg-sage
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 0 updates, 2 removals
  - Removing nothingworks/blade-svg (v0.3.0)
  - Removing log1x/blade-svg-sage (v2.0.0)
Writing lock file
Generating autoload files
$ composer require log1x/blade-svg-sage
Using version ^2.0 for log1x/blade-svg-sage
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing nothingworks/blade-svg (v0.3.0): Loading from cache
  - Installing log1x/blade-svg-sage (v2.0.1): Loading from cache
Writing lock file
Generating autoload files

Reloading my page (which had been working fine with aforementioned hack) again reproduces that same error message:

Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined function app() in /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/nothingworks/blade-svg/src/helpers.php:15
Stack trace:
#0 /srv/www/bgr/htdocs/wp-content/uploads/cache/7d3bd42e63db143eb70e0949ad11f6f15a6d4e1f.php(5): svg_image('bg-heading-1', 'bg-abs color-re...')
#1 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/Engines/PhpEngine.php(43): include('/srv/www/bgr/ht...')
#2 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/srv/www/bgr/ht...', Array)
#3 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/srv/www/bgr/ht...', Array)
#4 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents()
#5 /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/illuminate/view/View.php(90): Illuminate\View\ in /srv/www/bgr/htdocs/wp-content/themes/bgr/vendor/nothingworks/blade-svg/src/helpers.php on line 15

I've reapplied my hack in order to continue development of my project. Happy to test again later.

@Log1x
Copy link
Owner

Log1x commented Nov 28, 2018

Are you calling the function directly or with the Blade directive?

@farmerpaul
Copy link
Author

Just using the Blade directive. For example: @svg('logo')

@Log1x
Copy link
Owner

Log1x commented Nov 28, 2018

Can you make sure the Blade cache is cleared? I see in your stack trace it's calling svg_image('bg-heading-1', 'bg-abs color-re...') but it should now call App/svg_image('bg-heading-1', 'bg-abs color-re...')

@farmerpaul
Copy link
Author

Good call, sorry about that. I was clearing my cache before but forgot to this time! Cheers, it works.

@Log1x
Copy link
Owner

Log1x commented Nov 28, 2018

Great! Thanks for testing. Let me know if you find any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants