I am getting the error:
PHP Fatal error: Class 'Symfony\\Component\\Process\\PhpProcess' not found in ...
It's my first time using Symfony. I download the files from the GitHub site. Since the downloaded files are of the Process directory, I created folders in order to have the correct path. (Symfony/Component/Process/DOWNLOADED FILES).
I placed the Symfony directory in the main directory (where my index file is).
Is this how you install Symfony? (Note I only need the Process sub-directory and not the whole framework)
For now I am using this ready-made code, just to see if I can get it running:
use Symfony\Component\Process\PhpProcess;
$command = file_get_contents('/hello_world.php');
if ( $command ) {
$process = new PhpProcess($command); //<----- GETTING ERROR HERE
$process->run();
if ($process->isSuccessful()) {
$output = $process->getOutput();
// ...
}
else {
throw new Exception($process->getErrorOutput());
}
}
Why am I getting this error and how can I fix it please? Is it due to a bad path?
I think it has to do with namespace registration, have you checked that the namespace that defines the class is loaded?, check the ClassLoader reference
Check the autoload.php file inside your app directory
Related
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
I'm a google recaptcha v2 on a local machine running wamp. Everything looks fine except it keeps dying when its supposed to validate the form
I'm getting this error:
Fatal error: Class 'ReCaptcha\RequestMethod\Post' not found in C:\wamp\www\php\contactForm\Captcha\ReCaptcha.php on line 73
I've pretty much copy/pasted the example code from google:
if (!empty($human)) {
require_once('Captcha\ReCaptcha.php');
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($human, $remoteIp);
if ($resp->isSuccess()) {
// verified!
I've downloaded the files from the google github (https://github.com/google/recaptcha/tree/master/src/ReCaptcha) and just used the folder /files names as they came. I've got my validation file one folder above but I've also tried coping the files into the same folder as my validation script just in case.
Any ideas?
It seems google bank on the fact that everyone use composer to install their repository. And to be honest that is the only installation method they give on thier github repo readme.md https://github.com/google/recaptcha
When you install a package such as google recaptcha with composer the package has the option to register with an autoloader in https://github.com/google/recaptcha/blob/master/composer.json
"autoload": {
"psr-4": {
"ReCaptcha\\": "src/ReCaptcha"
}
},
This way all you have to include in your script to get access to all your package classes is the autoload.php that composer generates when it installs your packages.
Line 34: https://github.com/google/recaptcha/blob/master/examples/example-captcha.php
// Initiate the autoloader.
require_once __DIR__ . '/../vendor/autoload.php';
An autoloader is a function that tries to load a class when php is asked for it. And in this case it kind of maps a namespace to a directory structure on the disk.
More about php autoloaders here: http://php.net/autoload and here: http://www.php-fig.org/psr/psr-4/examples/
If you do not wish to use composer and its autoload functionality, you may find this useful: https://github.com/abraham/twitteroauth it has an autoload.php which you could borrow which can load classes without composer.
Place a copy of it in your recaptcha top level folder (the one with README.md in it)
Replace line 12 with $prefix = 'ReCaptcha\\';
replace line 15 with $base_dir = __DIR__ . '/src/ReCaptcha/';
Require autoloader.php (this file) in your code somewhere
Instantiate your ReCaptcha object something like this in your code
new ReCaptcha\ReCaptcha($RECAPTCHASECRETKEY);
I hope I don't get slammed to hard but I found if you require all of the files it works as designed without using an autoloader or composer.
//GOOGLE RECAPTCH CODE
require_once('/cgi-bin/src/ReCaptcha/ReCaptcha.php');
require_once('/cgi-bin/src/ReCaptcha/RequestMethod.php');
require_once('/cgi-bin/src/ReCaptcha/RequestParameters.php');
require_once('/cgi-bin/src/ReCaptcha/Response.php');
require_once('/cgi-bin/src/ReCaptcha/RequestMethod/Post.php');
require_once('/cgi-bin/src/ReCaptcha/RequestMethod/Socket.php');
require_once('/cgi-bin/src/ReCaptcha/RequestMethod/SocketPost.php');
$gRecaptchaResponse = $_POST['g-recaptcha-response'];
$secret = 'YOUR SECRET KEY';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
//DO ACTION IF SUCCESSFUL
} else {
$errors = $resp->getErrorCodes();
}
//END OF GOOGLE RECAPTCHA CODE
I've created a phar of a Symfony2 web application, but I'm having some troubles with the cache-folders.
I found out that I could mount an external file/folder into a phar. That would fix my issue, but I can't get the example on the PHP site working.
I have a phar which contains an index.php:
<?php
$configuration = simplexml_load_string(file_get_contents(
Phar::running(false) . '/config.xml'));
?>
Then I include the .phar with the following code:
<?php
// first set up the association between the abstract config.xml
// and the actual one on disk
Phar::mount('phar://config.xml', '/var/www/$projectname/config.xml');
// now run the application
include 'phar-archive.phar';
?>
All files exists, but I get the following error:
PHP Fatal error: Uncaught exception 'PharException' with message 'config.xml is not a phar archive, cannot mount' in /var/www/$projectname/index.php:3
I already tried relative/absolute paths, changing permissions but can't get this to work. Additionally a working example of how I could mount a folder into a phar would be great !
First check that variable $projectname exist in this place (just run echo $projectname; before Phar::mount). If all ok, then change
Phar::mount('phar://config.xml', '/var/www/$projectname/config.xml');
to
Phar::mount('phar://config.xml', "/var/www/{$projectname}/config.xml");
It seems that variable $projectname not converted to its value because you used single quotes.
im a PHP newbie . .
i've tried to make a PHAR of my project.
my project include 5 directories and multiply classes within each dir.
I've followed this tutorial
Phar – PHP archiving practice
and i did the following:
to my main index.php i added this lines:
$sLibraryPath = 'lib/myPhar.phar';
// we will build library in case if it not exist
if (! file_exists($sLibraryPath)) {
ini_set("phar.readonly", 0); // Could be done in php.ini
$oPhar = new Phar($sLibraryPath); // creating new Phar
$oPhar->setDefaultStub('index.php', 'classes/index.php'); // pointing main file which require all classes
$oPhar->buildFromDirectory('classes/'); // creating our library using whole directory
$oPhar->compress(Phar::GZ); // plus - compressing it into gzip
}
and i created a new folder called classes , and created a index.php file within it, and there i included all my project classes.
i've chmod 777 the following directories: lib, HelloWorld , HelloWorld/index.php ,
and changed the phar.readonly. (phar.readonly = 0)
still i get this message:
Fatal error: Uncaught exception 'PharException' with message 'unable to create temporary file' in /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php:10 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php(10): Phar->setDefaultStub('index.php', 'classes/index.p...') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php on line 10
i havent found any helpful info what to do with it, and i will glad for your help.
(if there is a better way to create PHAR it will be fine)
I'm not sure if it is the point, but check this link Bug #63112 PharException when compiling
May be you have the same trouble with temp directory?
Use the PHP2Phar package to create your Phar file from PHP files.
Link:
https://github.com/00F100/php2phar
Usage:
$ php php2phar.phar --dir-source <path/to/dir> --index-file </path/to/index.php> --output-file <path/to/file.phar>
I'm wondering why I got this error when installing sfDoctrineGuard plugin in symfony 1.4 project
stack trace:
SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Table.php line 2856 ...
return call_user_func_array(array($this->getRecordInstance(), $method . 'TableProxy'), $arguments);
} catch (Doctrine_Record_UnknownPropertyException $e) {}
throw new Doctrine_Table_Exception(sprintf('Unknown method %s::%s', get_class($this), $method));
}
}
The problem occurs when you run doctrine build all or build model command from the command line.
If the sf_guard_user table exists in your database, running either of these commands generates an empty SfGuardUserTable class in your \lib\model folder and this gets used instead of the sfGuardUserTable class sitting in your plugin folder, which does contain a retrieveByUsername method.
Removing the SfGuard____ classes from inside your lib folder would fix the problem.
I used the build commands quite often and got a bit fed up with doing this each time. I eventually moved the code from within the plugin folder into the lib directory which isn't really recommended. But I don't think the sfGuardUser plugin is maintained any more, so if you know what you're doing you could give it a try.