PhantomJs cannot execute binary file - php

I am trying to use PhantomJs in my laravel 5 project. I have downloaded via composer. I have added into my providers section and aliases section within config/app.php
Okay so i have now created my controller as seen below:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use PDF;
use View;
class PdfController extends Controller {
public function index()
{
$view = View::make('home');
return PDF::createFromView($view, 'home.pdf');
}
}
I have also created my route for this method. However when i try this in my browser it throws the following error:
PhantomJS: sh: /Users/matts/sites/ManagementApp/vendor/antking/phantom-pdf/src/../bin/phantomjs: cannot execute binary file
Has anyone come across this before?
Thanks

The "cannot execute binary file" indicates that it was not able to run phantomjs at all, and it is probably not related to your code. The most likely reason for this is an architecture incompatibility. Depending on whether or not you have a 32 or 64 bit system, you should use either phantomjs-1.9.8-linux-x86_64 (64bit) or phantomjs-1.9.8-linux-i686. It is possible that you used the wrong one for your system.

Related

Laravel using package [Requests for PHP]

I am using Laravel 6.5.2 and trying to use the package "Requests for PHP". https://requests.ryanmccue.info/download/
I installed this package using composer. The reason I want to use this packages is that I have all CRUD scripts created (using above package) and would like to reuse the scripts.
I suspect there might be some name conflict since Laravel comes installed with a HTTP request solution called Request, meanwhile the [PHP Request] has the same name.
Question:
Has anyone succesfully installed [Requests for PHP] package and got it to work with Laravel 6.X ?
Other findings:
Whe comment-out the autoloader line, the corresponding page prints "hello" as it should. Leaving this line active indicates in the laravel stack trace that the error is the line that holds the autoloader.
[Error]
Class 'App\Http\Controllers\Requests' not found
[routes/web.php]
Route::get("/requests", "Requests#read");
[app/Http/Controllers]
<?php
namespace App\Http\Controllers;
// use Illuminate\Http\Request; // Standard line, creeating a controller.
require_once '../vendor/rmccue/requests/library/Requests.php';
Requests::register_autoloader();
class Requests extends Controller {
public function read() {
echo "hello";
}
}

Laravel default helper method and facade doesn't work on custom package

I am developing a custom package where I need an access to the config data. I was able to pull data from config through my blade files, however, when I tried to call it from any custom classes I made, it's throwing an error:
Error: Call to undefined function Acme\Package\config()
What's interesting though, is that, when I tried using the facade Illuminate\Support\Facades\Config, it cannot find the class.
Is there any way I could retrieve data from the config (from the package and/or the app)?
<?php
namespace Acme\Package;
class MyClass {
public function test() {
config('app.name');
}
}
UPDATE: It works when running in the browser (package installed in a Laravel project) but fails when running package's test
UPDATE: If this helps, my package can be found here
Call to the config() is from here
And the test case that fails can be found here
<?php
namespace Acme\Package;
class MyClass {
public function test() {
\Illuminate\Support\Facades\Config::get('app.name');
}
}
Try like this, to use the full namespace to the Config Facade. You could also make a use statement under your namespace to inject the facade and then use Config::get('app.name). The reason it is not working is that your package cannot resolve the namespace of that facade as it is outside of the IoC container
You should try this:
<?php
namespace Acme\Package;
use Config;
class MyClass {
public function test() {
Config::get('app.name');
}
}
Updated answer
Please add below line in config/app.php in aliases section
'Config' => Illuminate\Support\Facades\Config::class,
then run below command
php artisan config:cache
php artisan cache:clear

How can I take a screenshot using duncan3dc/dusk library?

I am using the duncan3dc module in laravel, Successfully importing text from the default example But I do not know how to take a screenshot,
I just installed this module using Composer.
$ composer requires duncan3dc/dusk.
Does it mean that everything needed for this module is automatically installed?
Or do I need something else to take a screenshot?
Below is my controller code
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use duncan3dc\Laravel\Dusk;
class TestController extends Controller
{
public function test()
{
$dusk = new Dusk;
$dusk->visit("http://example.com");
$dusk->screenshot("ddd");
echo $dusk->element("h1")->getText() . "\n";
}
}
When I run the above code, I get this error:
file_put_contents (/tmp/ddd.png): failed to open stream: No such file
or directory
I think there is no folder, so I get the error, where should I create the folder in the project folder?
According to the changelog from version 0.8.0 you can pass fully qualified path to screenshot method. So doing this will work (you should see the file ddd.png created near the php file):
$dusk = new Dusk;
$dusk->visit("http://example.com");
$dusk->screenshot("./ddd.png");
echo $dusk->element("h1")->getText() . "\n";
You can also pass absolute path:
$dusk->screenshot("C:\windows\temp\ddd.png"); // if you are using windows
or
$dusk->screenshot("/tmp/ddd.png"); // if you are using macos/linux

Laravel dependency injection does not find the class

I'm using PHPUnit to test my application, in this case I'm testing an API call (I'm doing GET, POST, PUT and DELETE through it). index method responds to GET(/api) route, in this method I have a custom Request:
public function index(\Api\User\Requests\IndexRequest $request)
{
// do some stuff...
}
Api\User\Requests\IndexRequest class looks like this:
class Request extends IndexApiRequest
{
// some methods in here
}
When I execute the test via PHPUnit it prompts:
Class Api\User\Requests\IndexRequest does not exist
Checking the trace route it dies in Illuminate\Routing\RouteDependencyResolverTrait. I couldn't figure out how I can interfere in the execution since it seems to happen between PHPUnit and Laravel.
Does anyone have an idea? I'm using Laravel 5.3, PHPUnit 5.6.5 running on Ubuntu 16.04, PHP 7.0 and nginx.
Thank you!
change class Request extends IndexApiRequest to class IndexRequest extends IndexApiRequest

ClassNotFoundException: Attempted to load class "Mongo" from... (with persist) symfony2

I am having some issue integrating mongodb with Symfony (version 2.5.0-DEV) using the doctrine mongodb cookbook on http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html.
Everything is okay up to the 'Persisting Objects to MongoDB' stage. When I add the line "$dm->persist($script);", nothing happens to my remote database and I get the error message:
ClassNotFoundException: Attempted to load class "Mongo" from the global namespace in /var/www/Symfony/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Connection.php line 283. Did you forget a use statement for this class?
But without the persist line, the script parses without errors (but nothing happens at the remote database).
Is this particular to my Symfony version (2.5.0) and is there a workaround? I have pasted my entire script below including the use statements. Any help would be appreciated :).
namespace Atlas\MpBundle\Controller;
use Atlas\MpBundle\Document\Scripts;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class UserjsonController extends Controller
{
public function showuserjsonAction()
{
$script = new Scripts();
$script->setName('kingstest');
$script->setDescription('just a desc test');
$script->setGroup('SMS');
$dm = $this->get('doctrine_mongodb')->getManager();
$dm->persist($script);
$dm->flush();
return new Response('Created New Document in scripts with script id '.$script->getId());
}
}
Thanks guys. Works now.
the extension mongo.so has to be loaded in php.ini and I edited the wrong php.ini file. Added extension=mongo.so to php.ini located in /etc/php5/apache2/ and now it works :)
Hopefully this can help someone in the future.

Categories