Intervention causing reload of page? - php

I'm probably using it wrong and not understanding the purpose properly. But as a simple test, I added the following in my "master.blade.php" file:
if (!file_exists('images/cache/clients/'.$image)) {
$img = Image::make('images/clients/'.$image)->resize(null, 50, true);
$img->save('images/cache/clients/'.$image);
}
The problem is that when it hits this code, it basically reloads the entire frontpage. SO I see the content twice. It's like the make function actually does some header response of some kind.
All I want to do is resize the image, and save it to another location. What am I missing?
UPDATE
I have this in my composer.json file:
"require": {
"laravel/framework": "4.1.*",
"way/generators": "dev-master",
"laravelbook/ardent": "dev-master",
"codesleeve/stapler": "dev-master",
"phpseclib/phpseclib": "0.3.*",
"chumper/datatable": "dev-master",
"moltin/laravel-cart": "dev-master",
"intervention/image": "1.*",
"opauth/opauth": "0.4.x",
"artdarek/oauth-4-laravel": "dev-master"
},
I am unsure whether this should be added anywhere:
use Intervention\Image\Image;
(this page isn't exact if this should be added for laravel, or where it should be added for laravel)
I've got:
GD bundled (2.1.0 compatible)
PHP 5.5.11
Any ideas what's wrong?
UPDATE2
Make just does this:
public static function make($source)
{
return new static($source);
}
I've tried wrapping make around an exception, no luck. But even if I do this:
public static function make($source)
{
$bla = new static($source);
print 'xxx'; die();
}
I don't see the print 'xxx' happening. If I put it before the "new static" part, I do see it. So basically, it's bombing on "new static". Is there any reason why this should happen on PHP 5.5?
** THINK I GOT IT **
I took everything out and placed it before the app even runs. Now I get this error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Call to undefined function Intervention\Image\finfo_buffer()
This is saying libjpeg might be the issue, but it seems I do have it in my PhpInfo:
libJPEG Version 9 compatible
I'm running xampp, and apparrently I need this in the php.ini file:
extension=php_fileinfo.dll
I've added it but have to restart my machine to see the effect (dont ask, my xampp is broken)... will report back in a sec.

The problem was not having fileinfo enabled. I added this in my php.ini file:
extension=php_fileinfo.dll
That did the trick. A bit of a bummer that the addon didn't make it apparent.
Thanks for the downvote, but I'm sure this will help someone else trouble-shoot this problem.

Related

Symfony 4.x public dir rename to public_html

I got a little struggle with renaming dir to public_html for web host.
According to latest tutorial I'm trying to successfully rename it, but every time when i'm trying to run local server using console command I'm getting an error:
[ERROR] The document root directory ".../.../App/public" does not exist.
I'm sure that I'm doing something wrong with code. But I don't know where. I'm very beginner with Symfony.
Here's my code from composer.json:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
}
"public-dir": "public_html"
},
Did I understood something wrong with it?
Thanks for help.
If the code snippet represents exactly what you have in your composer.json then I have noticed that it is not correctly formatted json file. In the "extra", after the value of "symfony" key, you need to put a separator "," then in the next line you may add more key:value pairs. AS in:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
},
"public-dir": "new_public_html_dirname"
}
A not well formatted json file will prevent it from being executed. I hope it helps.
It is important to run composer update.
composer update
As the index.php file is the first file being run (by the webserver) you should just be able to rename the public directory to public_html and it will work, and not need to change anything in the composer.json (though how that would affect the framework code, without at least running any composer-scripts, I do not know).
I've just created a new Symfony 4.2.3 project, and done nothing more than renaming the directory, and running (most) bin/console commands are not affected.
The in-built server will have issues, but you can tell it which directory to use as the docroot with:
mv public public_html
bin/console server:start --docroot=public_html/
[OK] Server listening on http://127.0.0.1:8000
The changes to composer.json are not required.

pdftk: PHP Fatal error: Class 'mikehaertl\pdftk\Pdf' not found in

I have a project in Slim framework. There are multiple composer packages. Now, I have added https://github.com/mikehaertl/php-pdftk to fill PDF but I'm getting PHP Fatal error: Class 'mikehaertl\pdftk\Pdf' not found in... What is wrong with my code?
composer.json:
{
"require": {
"dibi/dibi": "^3.0",
"slim/slim": "^3.7.0",
"phpmailer/phpmailer": "^5.2",
"jbroadway/urlify":"^1.1.0",
"simplesoftwareio/simple-qrcode":"^1.5.1",
"gopay/payments-sdk-php":"^1.2.3",
"mikehaertl/php-pdftk":"^0.4.2"
}
}
in my ./config/config.php there is:
define('PATH', dirname(__DIR__));
require_once PATH."/vendor/autoload.php";
and in my ./methods/controller.php:
...
$pdf = new mikehaertl\pdftk\Pdf("/path/to/QR_template.pdf");
...
I tried to get names of all included files by using:
var_dump(get_included_files());
but the "pdf" files were not in the array.
Other packages works well but pdftk not. Where is the problem?
Thank you.
Solved! The problem was composer version. Composer self-update solved the problem.

Slim/Http/Environment not found in PHPUnit test

I'm developing an API with Slim/Composer and I am currently trying to implement some unit testing with PHPUnit. I keep running into an error when I run the test via command line:
Fatal error: Class 'Slim\Http\Environment' not found
in C:\workspace\client\website\client\api\client-api\src\testclasses\dao\GenreDaoTest.php
on line 15
My composer.json looks like this:
{
"require": {
"slim/slim": "^3.1",
"slim/php-view": "^2.0",
"monolog/monolog": "^1.17",
"robmorgan/phinx": "^0.5.1",
"firebase/php-jwt": "^5.0",
"vlucas/phpdotenv": "^2.4",
"tuupola/slim-jwt-auth": "^2.3"
},
"autoload": {
"psr-4": {
"": ["classes/dao",
"classes/controller",
"classes/app",
"testclasses/dao"]
}
},
"require-dev": {
"phpunit/phpunit": "^5.7"
}
}
My test class looks like this:
<?php
use \Slim\Http\Environment as Environment;
use \Slim\Http\Request as Request;
use \Slim\Http\Response as Response;
class GenreDaoTest extends \PHPUnit_Framework_TestCase {
public function testTemp() {
$this->assertEquals(0, 0);
}
public function testGenres() {
$environment = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/api/v1/genres'
]);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = new Response();
$this->assertEquals('test', 'test');
}
}
?>
If I comment out the entire 2nd test, leaving the use statements, the first test will pass with no problem. I thought maybe it was something to do with the location of the test file, so I moved it to the classes/app directory where I have other classes with similar imports, and I'm seeing the same results, so I don't think it's and issue with where the file lives.
The only 2 things I can think of is that something is happening when I run the test via the command line ($phpunit src/testclasses/dao/GenreDaoTest.php) or something is wrong with my Composer setup.
I'm a Java engineer usually, so I may be missing something simple in the PHP realm, too :)
Anyone have any suggestions? I greatly appreciate it!
(also, I understand that I probably shouldn't be testing API requests/responses in a test for a DAO, I'm in the process of refactoring)
When using phpunit you can tell it to include vendor/autoload.php before running tests. To do so you can change phpunit.xml to include this:
<phpunit bootstrap="./vendor/autoload.php">
...
</phpunit>
Or you can pass --bootstrap vendor/autoload.php to phpunit command when invoking it from command line:
phpunit --boostrap vendor/autoload.php <tests directory>
Read more in PHPUnit documentations under section Test Execution.
I also suggest reading this question and its answers.
I'm using Slim 4 and had the same problem.
I changed :
use \Slim\Http\Request as Request;
by
use Slim\Psr7\Environment;
and works for me !!!

Need help in overcoming the incompatibility of a certain behat dependencies set with a PHP 5.3

I was having a certain behat configuration with a specific dependencies set which worked well with PHP 5.5. But later I've had to transfer that configuration to a server with jenkins. The trouble is that server has PHP 5.3 installed with no possibility to be updated.
Despite dependencies refused to be installed via composer in a normal way, I've forced them to be installed anyway using the "--ignore-platform-reqs" parameter.
Having installed the dependencies, I've faced with another issue which I could not had overcome that easily. It simply displays an error while attempting to execute "bin/behat" command:
PHP Parse error: syntax error, unexpected '[' in .../workspace/automated-tests/vendor/guzzlehttp/psr7/src/functions.php on line 77
PHP Stack trace:
PHP 1. {main}() .../workspace/automated-tests/vendor/behat/behat/bin/behat:0
PHP 2. includeIfExists() .../workspace/automated-tests/vendor/behat/behat/bin/behat:21
PHP 3. include() .../automated-tests/vendor/behat/behat/bin/behat:17
PHP 4. ComposerAutoloaderInit617eef80953ba1e8b93feeaeccb52bc0::getLoader() .../workspace/automated-tests/vendor/autoload.php:7
PHP 5. composerRequire617eef80953ba1e8b93feeaeccb52bc0() .../workspace/automated-tests/vendor/composer/autoload_real.php:49
PHP 6. require() .../workspace/automated-tests/vendor/composer/autoload_real.php:59
Parse error: syntax error, unexpected '[' in .../workspace/automated-tests/vendor/guzzlehttp/psr7/src/functions.php on line 77 Call Stack: 0.0006 645368 1. {main}() .../workspace/automated-tests/vendor/behat/behat/bin/behat:0 0.0008 645976 2. includeIfExists() .../workspace/automated-tests/vendor/behat/behat/bin/behat:21 0.0016 649328 3. include('.../workspace/automated-tests/vendor/autoload.php') .../workspace/automated-tests/vendor/behat/behat/bin/behat:17 0.0021 680968 4. ComposerAutoloaderInit617eef80953ba1e8b93feeaeccb52bc0::getLoader() .../workspace/automated-tests/vendor/autoload.php:7 0.0082 1106296 5. composerRequire617eef80953ba1e8b93feeaeccb52bc0() .../workspace/automated-tests/vendor/composer/autoload_real.php:49 0.0089 1109928 6. require('.../workspace/automated-tests/vendor/guzzlehttp/psr7/src/functions_include.php') .../automated-tests/vendor/composer/autoload_real.php:59
Here's the list of dependencies in composer.json:
{
"require": {
"behat/gherkin": "~4.4",
"drupal/drupal-extension": "~3.1",
"emuse/behat-html-formatter": "dev-master"
},
"require-dev": {
"bossa/phpspec2-expect": "~1.0",
"ocramius/proxy-manager": "~0.5",
"phpunit/phpunit": "~4.5",
"jakoch/phantomjs-installer": "1.9.8"
},
"autoload": {
"psr-0": {
"Behat\\Behat": "src/",
"Behat\\Testwork": "src/"
}
},
"config": {
"bin-dir": "bin/"
}
}
Short array syntax [] was added in PHP 5.4, so I guess you're running some older version of PHP on the shared server. Normally replacing [] with array() would help, but here it is an external vendor package so it's not advised to modify the code as changes would be overwritten when vendor package is updated. Other than that the only way to fix that issue is to use newer version of PHP.
From this related question
I've found a solution to the problem. I've changed the "require" block in composer.json to the following:
{
"require": {
"drupal/drupal-extension": "*",
"emuse/behat-html-formatter": "dev-master"
},
Notice that I've got rid of the ""behat/gherkin": "~4.4"" and changed drupal/extension version to "*". Thus it downloads the latest and most stable version along with all dependencies it requires (so behat 4 is included as well) according to the specs of my system (so its PHP 5.3 compatible).
At least that's the way I see it. Please, correct me If I'm wrong.

PHP: MDB2 error - call to undefined function

I have error in my old project based od MDB2 and PHP 5.4:
PHP Fatal error: Call to undefined function: MDB2_Driver_pgsql::raiseError(). in /path/to/project/vendor/pear-pear.php.net/MDB2/MDB2.php on line 1936
Dependencies loaded via composer:
"require": {
"pear-pear.php.net/Validate": "0.7.0",
"pear-pear.php.net/Validate_PL": "0.5.1",
"pear-pear.php.net/HTML_Quickform": "*",
"pear-pear.php.net/HTML_Table": "*",
"pear-pear.php.net/MDB2": "*",
"pear-pear.php.net/MDB2_Driver_pgsql": "*",
"pear-pear.php.net/OLE": "1.0.0RC1",
"pear-pear.php.net/Spreadsheet_Excel_Writer": "0.9.1",
"pear-pear.php.net/File_SearchReplace": "*",
And I don't change anything in this code. Anyone had this problem? :)
This error is solved by installing PEAR-1.9.5
I've spent some time to find easy way to downgrade PEAR version.
It's easy to do by running terminal command:
pear install -f PEAR-1.9.5
Hope this will help someone to save extra time.

Categories