Error itself:
2021-07-20T23:43:33.993462+00:00 app[web.1]: [20-Jul-2021 23:43:33 UTC] [critical] Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "SQLite3Cache" from namespace "Doctrine\Common\Cache".
2021-07-20T23:43:33.993688+00:00 app[web.1]: Did you forget a "use" statement for another namespace?" at /app/src/Utils/FilesCache.php line 23
The file contents of "FilesCache.php" are similar to what's provided in Symfony's documentation here with a few additions.
<?php
namespace App\Utils;
use App\Utils\Interfaces\CacheInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\SQLite3Cache;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
class FilesCache implements CacheInterface
{
public $cache;
public function __construct()
{
//this is error line 23
$provider = new SQLite3Cache(new \SQLite3(__DIR__ . '/cache/data.db'), 'TableName');
$this->cache = new TagAwareAdapter(
new DoctrineAdapter(
$provider,
$namespace = '',
$defaultLifetime = 0
)
);
}
}
I've added both "pdo_sqlite" and "sqlite3" extensions to "composer.json".
Composer update runs without issue.
I'm committing both the "composer.json" and "composer.lock" before pushing the local project repo to Heroku, which runs without issue as well and shows that both extensions are added.
remote: -----> Installing platform packages...
remote: - php (8.0.8)
remote: - ext-intl (bundled with php)
remote: - ext-pdo_sqlite (bundled with php)
remote: - ext-sqlite3 (bundled with php)
remote: - composer (2.1.3)
remote: - apache (2.4.48)
remote: - nginx (1.20.1)
I know that SQLite isn't the proper choice for a production database, I'm following a course and I'd like to continue using what's provided from it.
Thank you in advance for any help!
As mentioned in the comments, the problem was the deprecation of doctrine/cache. I switched to a PDOAdapter and this fixed the issue.
<?php
namespace App\Utils;
use App\Utils\Interfaces\CacheInterface;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Adapter\PdoAdapter;
use Doctrine\DBAL\Driver\Connection;
class FilesCache implements CacheInterface
{
public $cache;
public function __construct()
{
$connection = \Doctrine\DBAL\DriverManager::getConnection([
'url' => 'sqlite:////%kernel.project_dir%/var/cache/data.db'
]);
$this->cache = new TagAwareAdapter(
new PdoAdapter(
$connection,
$namespace = '',
$defaultLifetime = 0
)
);
}
}
Related
I'm getting a fatal server error when trying to create an instance of Googles's TextToSpeechClient class while deploying PHP app on App Engine flex environment. On localhost it works without any issue. Below is the error message:
"NOTICE: PHP message:
PHP Fatal error: Uncaught Error: Class
'Google\Cloud\TextToSpeech\V1\TextToSpeechClient' not found in
/app/web/get_voices2.php:46"
My get_voices2.php
<?php
// includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
require_once('includes/dbPDO.php');
// Imports the Cloud Client Library
use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
use Google\Cloud\Storage\StorageClient;
if (isset($_POST['language']) && isset($_POST['quality'])) {
$storage = new StorageClient();
$language = $_POST['language'];
$quality = $_POST['quality'];
$dsn = getenv('MYSQL_DSN');
$user = getenv('MYSQL_USER');
$password = getenv('MYSQL_PASSWORD');
$dbh = OpenCon($dsn,$user,$password);
echo getListVoices($language, $quality, $dbh);
}
function getListVoices($lan, $quality,$conn) {
$optionData = '<option id = "0" disabled>Select voice</option>';
// instantiates a client on line 46
$client = new TextToSpeechClient(['credentials' => json_decode(file_get_contents('cred.json'), true)]);
$response = $client->listVoices();
$voices = $response->getVoices();
}
Here is my App Engine folder structure. Please mention that app.yaml file is not in the web directory. It's in the same dir as /various and /php-docs-sample
PHP app's web directory structure
My composer.json file:
{
"require": {
"google/cloud-speech": "^1.0.1",
"google/gax": "^1.1",
"grpc/grpc": "^1.4",
"google/protobuf": "^v3.3.0",
"google/auth": "^1.8",
"phpseclib/phpseclib": "^2.0"
}
}
I deploy my project on App Engine by running the command:
gcloud app deploy -version dev
I hope I gave complete information.
According to it's repository, that class is given in the package google/cloud-text-to-speech - but according to your composer.json, you haven't required that package.
Why did you require google/cloud-core in the require-dev section after all? That's a good sign that you use a different set of application-specific classes for your development system than for production. Usually, this should only include stuff that is part of your development (like: debugging tools, test tools), but not those that provide the base of your application
I just follow up my question with a solution that worked. As #Nico Haase mentioned in his answer, after executing:
$ composer require google/cloud-text-to-speech
Instead of:
$ composer require google/cloud-speech
Composer automatically added the following line to composer.json
{
"require": {
"google/cloud-text-to-speech": "^1.0"
}
}
Then the client was instantiated without any problem
$client = new TextToSpeechClient();
I'm having hard time to configure a BitBucket pipeline to deploy a CakePHP application to a hosting server.
Reading some tutorials I've ended up with this pipeline:
image: edbizarro/bitbucket-pipelines-php7
pipelines:
branches:
master:
- step:
caches:
- composer
script:
- composer install --no-interaction --no-progress --prefer-dist
- composer test
- composer deploy-to-production
but it always fails:
Build setup -> OK
composer install -> OK
composer test -> FAIL
+composer test
phpunit --colors=always
Deprecated Error: Plugin::load() is deprecated. Use Application::addPlugin() instead. This method will be removed in 4.0.0. - /opt/atlassian/pipelines/agent/build/config/bootstrap.php, line: 179
You can disable deprecation warnings by setting Error.errorLevel to E_ALL & ~E_USER_DEPRECATED in your config/app.php. in [/opt/atlassian/pipelines/agent/build/vendor/cakephp/cakephp/src/Core/functions.php, line 311]
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
Exception: Unable to insert fixtures for "App\Test\TestCase\Controller\CustomersControllerTest" test case. SQLSTATE[HY000] [2002] No such file or directory in [/opt/atlassian/pipelines/agent/build/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php, line 380]
Script phpunit --colors=always handling the test event returned with error code 244
I cannot ls the virtual remote folders but I can mine... so I inspected App\Test\TestCase\Controller\CustomersControllerTest:
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\CustomersController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
class CustomersControllerTest extends TestCase
{
use IntegrationTestTrait;
public $fixtures = [
'app.Customers',
'app.Orders'
];
public function testIndex()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testView()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testAdd()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testEdit()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testDelete()
{
$this->markTestIncomplete('Not implemented yet.');
}
}
Because I'm not using tests, can I (safely) avoid the composer test step?
By the way, on the hosting server the PHP version is 5.6 while in the pipeline's image is specified version 7. Might this lead to a problem?
I'm trying to use Doctrine MongoDB ODM 2.0 beta on a project with the Yii2 framework, with composer version 1.8.4 and PHP 7.2, but I keep getting the error Fatal error: Uncaught Error: Call to a member function add() on boolean where the code runs $loader->add('Documents', __DIR__);
bootstrap.php file (in DIR/bootstrap.php):
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('fsa');
$config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Documents'));
$dm = DocumentManager::create(null, $config);
I already tried looking at How to properly Autoload Doctrine ODM annotations? and Laravel & Couchdb-ODM - The annotation "#Doctrine\ODM\CouchDB\Mapping\Annotations\Document" does not exist, or could not be auto-loaded and a host of other threads I can't quite recall for help, but I couldn't figure out a solution.
I also tried commenting out the lines below
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
and ran composer dump-autoload and on command line it returned Generated autoload files containing 544 classes, but then I got the problem
[Semantical Error] The annotation "#Doctrine\ODM\MongoDB\Mapping\Annotations\Document" in class Documents\Message does not exist, or could not be auto-loaded.
So the annotations are not auto-loading, and I have no idea how to fix that.
In the model I have:
<?php
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use \Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
/** #ODM\Document */
class Message
{
/** #ODM\Id */
private $id;
/** #ODM\Field(type="int") */
private $sender_id;
...
I also posted a thread on github at https://github.com/doctrine/mongodb-odm/issues/1976. One commenter stated that "By default, the composer autoload file returns the autoloader in question, which seems to not be the case for you." How can I fix that? The only information I can find online is to put (inside composer.json) the lines:
"autoload": {
"psr-4": {
"Class\\": "src/"
}
},
but then what class should I be loading?
I'm very confused and being pretty new to all these tools (mongodb, yii2, etc.) doesn't help at all. I'm not sure what other information would be helpful else I would post it.
Thanks in advance.
So turns out that the problem (as was mentioned in https://github.com/doctrine/mongodb-odm/issues/1976) was that autoload.php was required twice - once in bootstrap.php and once in web/index.php (of the framework). After the require line in index.php was removed, everything worked fine.
I installed a composer, downloaded the Aura, created an index.pxp and wrote in it:
require('vendor/autoload.php');
use Aura\Di\ContainerBuilder;
$builder = new ContainerBuilder();
$di = $builder->newInstance();
$object = $di->newInstance('Vendor\Package\ClassName');
But phpStorm says:Undefined namespase DI
And i have error: Fatal error: Class 'Aura\Di\ContainerBuilder' not found in... on line 4
I do as follows: http://auraphp.com/packages/3.x/Di/getting-started.html#1-1-1
In order for the composer auto-loader to pick up \Aura\Di, the dependency needs to be managed by composer.
You can easily do this by executing
composer require aura/di
which will add the dependency to your composer.json file and register with the auto-loader.
If you have manually downloaded and installed aura/di, you can revert that.
I installed Captcha bundle using this following Instruction:
Add "gregwar/captcha-bundle": "1.0.0" to require section in composer.json
Run Windows PowerShell in root and call php composer.phar update
Console outputs
Warning: PHP Startup: Unable to load dynamic library
'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego
modu│u. in Unknown on line 0 Loading composer repositories with
package information Updating dependencies (including require-dev)
Nothing to install or update Generating autoload files
Incenteev\ParameterHandler\ScriptHandler::buildParameters Updating the
"app/config/parameters.yml" file
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
Warning: PHP Startup: Unable to load dynamic library
'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego
modu│u. in Unknown on line 0
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
Warning: PHP Startup: Unable to load dynamic library
'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego
modu│u. in Unknown on line 0
// Clearing the cache for the dev environment with debug true
[OK] Cache for the "dev" environment (debug=true) was successfully
cleared.
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Warning: PHP Startup: Unable to load dynamic library
'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego
modu│u. in Unknown on line 0
Trying to install assets as relative symbolic links.
Bundle Method / Error
WARNING FrameworkBundle copy
WARNING JMSTranslationBundle copy
! [NOTE] Some assets were installed via copy. If you make changes to
these assets you have to run this command again.
[OK] All assets were successfully installed.
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget
Following instruction I can skip this step
// app/autoload.php
$loader->registerNamspaces(array(
// ...
'Gregwar' => __DIR__.'/../vendor/bundles',
));
but my autoload.php files looks following:
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
error_reporting(error_reporting() & ~E_USER_DEPRECATED);
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
I enabled bundle:
// app/appKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
);
}
Last instalation step is add gregwar_captcha: ~ to app/config/config.yml and it's done.
Now I'm trying to use it im my controller.
public function registrationAction(Request $request)
{
$user = new Models\User();
$form = $this->createFormBuilder($user)
->add('username', 'Symfony\Component\Form\Extension\Core\Type\TextType')
->add('birth', 'Symfony\Component\Form\Extension\Core\Type\DateType')
->add('captcha', 'captcha')
->add('save', 'Symfony\Component\Form\Extension\Core\Type\SubmitType', array('label' => 'Register'))
->getForm();
$form->handleRequest($request);
return $this->render(
'CassyW2Bundle:User:registration.html.twig',
array(
'form' => $form->createView(),
)
);
}
I get error:
Compile Error: Declaration of Gregwar\CaptchaBundle\Type\CaptchaType::buildView() must be compatible with Symfony\Component\Form\FormTypeInterface::buildView(Symfony\Component\Form\FormView $view, Symfony\Component\Form\FormInterface $form, array $options)
Where did I wrong?
See Doc. For your version of symfony you need another version of this bundle. Try installing it without providing version in composer.json.
According to the warning, try to install the php_yaml extension by downloading this from the PEAR's sitweb https://pecl.php.net/package/yaml.
Choose the stable version and copy the dll when extracted to **C:\xampp\php\ext**
https://github.com/symfony/symfony/blob/2.7/UPGRADE-2.1.md#form
If you check Upgrade docs which version related Symfony 2.1 FormTypeInterface changed and it is a BC break which used in
https://github.com/Gregwar/CaptchaBundle/blob/v1.0.0/Type/CaptchaType.php
So Symfony 2.8 is not compatible with this bundle version 1.0.0 There is version 2.0 tagged, please use this and if there is still problem open another question.