Class 'Imagine\\Imagick\\Imagine' not found Symfony 2.1 - php

I want to integrate the LiipImageBundle in my Symfony 2.1 project.
I installed the bundle and the imagine/Imagine v.0.4.0 bundle via composer.
It's seems to work fine, except, that the modified images are not saved.
The error.log states:
PHP Fatal error: Class 'Imagine\\Imagick\\Imagine' not found in /var/www/app/cache/prod/appProdProjectContainer.php on line 365
This line in appProdProjectContainer.php states:
protected function getLiipImagineService()
{
return $this->services['liip_imagine'] = new \Imagine\Imagick\Imagine();
}
I have no idea if this is correct or not. Have you guys any idea why PHP cannot find the class?

Have you added Imagine to autoload. If you haven't then u can do like this:
Open vendor/composer/autoload_namespaces.php
Add
'Imagine' => $vendorDir .'/imagine/Imagine/lib/',
'Liip\\ImagineBundle' => $vendorDir . '/liip/imagine-bundle/',

Related

PostHog namespace issue

I installed PostHog in my PHP codebase, and trying to use it by following the tutorial in this link (https://posthog.com/docs/integrate/server/php).
I am attempting to call PostHog::init function as a following:
PostHog::init($apikey,
array('host' => $baseUrl,
"debug" => true)
);
But I am getting error in this line PostHog::init, the error says
"Attempted to load class PostHog" from the global namespace. Did you forget a "use" statement?"
In fact, I am already using the "use" as following "use PostHog\PostHog;", but I am still getting this error. I can confrim that the Posthog library is intall becuase I can read the classess in Poshog library from my codebase.
This is more info about my app:
I use Symfony framework 5 and the app is deployed in docker. I use PHP 7.4 and posthog/posthog-php": "2.1.1".
I checked the vendor folder and PostHog is there (see photo attached)
I implemented service call PosthogHandler where I use PostHog functions (like init, capture and etc). I am calling functions' services from controller. But the issue is that the error appear in the PosthogHandler constructor in line PostHog::init, at PostHog initialisation stage. This is my PosthogHandler service class:
<?php
declare(strict_types=1);
namespace App\Posthogs;
use PostHog\PostHog;
use App\User\User;
class PosthogHandler
{
public function __construct($env, string $key, string $baseUrl)
{
PostHog::init($key,
array('host' => $baseUrl,
"debug" => true)
);
}
public function addEvent(string $eventName, User $user){
PostHog::capture(array(
'distinctId' => $user->getId()->id(),
'event' => $eventName
));
}
}
Any help, why I am getting above error?
The error indicates that your class file could not be autoloaded properly. You might want to check first that PostHog is present in vendor/autoload.php by creating a test file to check
<?php
require_once 'vendor/autoload.php';
var_dump(class_exists('Posthog\Posthog'));
If not you should try this command
composer dump-autoload
It works!
I have three vendor folders in (1) Frontend (1) Controller (3) Services.
Before, I only installed the PostHog library in services folder where I use PostHog functions. This didn't seem working despite the posthog lib appeared in vendor folder.
What it makes work and the error disappears when I installed the posthog lib in controller folder. I don't use posthog in controller at all, I am not sure why I need to install the posthog lib in controller folder in order to work. But eventually it works!

PHP Fatal error: Trait 'Illuminate\Foundation\Testing\DatabaseTransactions' not found when running a sample test in Laravel Plugin

I'm developping a package for Laravel 5.3+ ( My tests where developped in Laravel 5.3)
I have installed Laravel 5.4, downloaded laravel/browser-kit-testing, and follow upgrade guide.
Now, when I run my tests, I get :
PHP Fatal error: Trait 'Illuminate\Foundation\Testing\DatabaseTransactions' not found
I don't really understand why, because file exists.
In my BrowserKitTestCase.php, I have a reference to
$app = require __DIR__.'/../bootstrap/app.php';
But as I am in my package development folder, I don't think app.php exists, it might be the issue, but can't find out how to fix it...
I tried to change it to:
$app = require __DIR__.'/../../../../bootstrap/app.php';
where app can be found ( I am in /package/author/plugin/tests/ ) but it error remains the same...
Any idea what's happening???

create instance of class after installing package with composer - PHP

I just used composer to install Highcharts. after installing the package i have this path in my project, to lead to the file where the class Highcharts defined:
$_SERVER['DOCUMENT_ROOT']."/myapp/vendor/ghunti/highcharts-php/src/Highchart.php
so as i;m doing with other classes in my project i added this line in the beginning of my file:
require_once($_SERVER['DOCUMENT_ROOT']."/myapp/vendor/ghunti/highcharts-php/src/Highchart.php");
but when i try to create instance of this class, like:
$chart = new Highchart();
in my file i get this error:
Fatal error: Class 'Highchart' not found in ...
any idea what am i doing wrong? thx
Add
use Ghunti\HighchartsPHP\Highchart;
before new Highchart();
It may be usefull to take a look at official demos from the GitHub repository of the Highchart library.

How to load plugin files in cakephp 2.0

I am using linkedin plugin for my app. It was working fine for cakephp 1.3. I migrated to cakephp 2.x. I understand you need to load plugins like this
CakePlugin::load('Linkedin');
It worked. But in my plugin folder I have vendor folder. It is loaded using
App::import('Vendor', 'Linkedin.oauth', array('file' => 'OAuth' . DS . 'oauth_consumer.php'));
But it says cannot find oauth_consumer.
I appreciate any help.
*UPDATED *
I have added linkedin plugin to my app. I have loaded my plugin using CakePlugin::load('Linkedin');. Now I get error
Fatal error: Call to a member function get() on a non-object in ....\Controller\Component\LinkedinComponent.php on line 95
On line 95 of Linkedin component this is what is there
$consumer = $this->_createConsumer();
$result = $this->Consumer->get($key, $secret, $this->apiPath . $path);
It says the get method is not found on linkedincomponent. But the get method is in oauth_consumer.php.
I appreciate all your help
The plugin is not 2.x ready.
You will have to upgrade it yourself.
You could have easily figured that out looking at the folders and files.
In 2.x it would be
/Linkedin/Controller/Component/LinkedinComponent.php
etc (also note the casing which is important in 2.x)
Most likely you can use the above upgrade shells to do that and make the plugin 2.x compatible.

Class sfDoctrineRouteCollection not found

I'm starting a new project using SF 1.4.18 and sfDoctrine & sfDoctrineGuard plugins. I had both active at config/ProjectConfiguration.class.php as follow:
public function setup() {
$this->enablePlugins(
array(
'sfDoctrinePlugin',
'sfDoctrineGuardPlugin'
)
);
}
All is good so far but when I try to reach the URL http://inventario.devserver/backend_dev.php/sfGuardUser this error come up:
Fatal error: Class 'sfDoctrineRouteCollection' not found in /var/www/html/inventario
/plugins/sfDoctrineGuardPlugin/lib/routing/sfGuardRouting.class.php on line 59
I don't know what's causing the error because I follow every step at plugins docs. Any help or advice?
Symfony 1.4 is shipped with sfDoctrinePlugin. You shouldn't add the plugin on your own.
Remove the folder sfDoctrinePlugin from your /plugins folder, clear your cache and it will solve your issue.
It's exactly the same problem from this guy, on the official Symfony forum, in 2009.

Categories