How to set up a Symfony Standard Edition application without vendor, but with PEAR - symfony

I'm following the basic description of Symfony Standard Edition on how to set up a new application with Symfony 2.
The thing is, this and all other guides explains that I need to have a vendors directory, where I should place third part libraries, such as Doctrine, Swiftmailer and Symfony itself.
However, Zend Server PEAR already comes with almost all of those libraries. As you know, I can even update my Symfony and Doctrine versions with the pear update command.
The question is: how can I set up that basic application to effectively use my PEAR libraries and ignore the vendors directory?
This is my version of app/autoload.php:
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
'Sensio' => __DIR__.'/../vendor/bundles',
'JMS' => __DIR__.'/../vendor/bundles',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
'Monolog' => __DIR__.'/../vendor/monolog/src',
'Assetic' => __DIR__.'/../vendor/assetic/src',
'Metadata' => __DIR__.'/../vendor/metadata/src',
));
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
));
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
}
$loader->registerNamespaceFallbacks(array(
__DIR__.'/../src',
));
$loader->register();
AnnotationRegistry::registerLoader(function($class) use ($loader) {
$loader->loadClass($class);
return class_exists($class, false);
});
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// Swiftmailer needs a special autoloader to allow
// the lazy loading of the init file (which is expensive)
require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php';
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');
It's clear that the autoloader is being configured to load the libraries from the vendor directory. I wanna use the libraries that comes with the pear package, however. How would that be implemented?

Just edit app/autoload.php to point to your pear delivered packages. Be careful that you use the proper versions. Probably be safer to just use the packages delivered with Symfony and then add paths to any additional libraries.

Related

How to replace silex in a project and adapt it to php8

I have this in my project php.
$app = new Silex\Application();
$app->register(new DerAlex\Silex\YamlConfigServiceProvider(realpath(__DIR__ . '/config/settings.yml')));
$app->register(new \Knp\Provider\MigrationServiceProvider(), array(
'migration.path' => __DIR__.'/../migration',
));
I need to update the code to use php8.
All package are abandoned / archived.
I could replace silex/silex by spryker/silexphp.
I dont know how to replace this package to get settings.yml configutarion.
DerAlex\Silex\YamlConfigServiceProvider
Someone knows how can i do this?

Drupal 8.6 Commerce: in .install file without module_uninstall() remove tables from database. Why?

When uninstall module then why delete all table from database without module_uninstall() function in .install file.
Also, why create table without module_install() function
.install file code is only:
function commerce_quickpay_schema() {
$schema['webc_crypto_meta'] = [
'description' => 'Custom Cryptography Meta',
'fields' => [...],
'primary key' => ['wcm_id'],
];
$schema['webc_crypto_payment'] = [
'description' => 'Custom Cryptography Payment',
'fields' => [...],
'primary key' => ['wcp_id'],
];
return $schema;
}
Also, please, CREATE TABLE IF NOT EXISTS condition in .install file.
This is how it behaves, the tables defined in hook_schema will be created or removed from the database when the module is installed or uninstalled, the hook_install() or hook_uninstall() hooks should be used when you want to do something extra.
It is simply assumed that the database schema should be removed when a module is uninstalled and come back when installed, if you think about it, it makes perfect sense.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21database.api.php/function/hook_schema/8.7.x
"The tables declared by this hook will be automatically created when
the module is installed, and removed when the module is uninstalled.
This happens before hook_install() is invoked, and after
hook_uninstall() is invoked, respectively."

Display images uploaded on amazon S3 with symfony2

Which is the best practice to show images from a remote amazon s3 repos on a symfony2 project?
I used KnpGaufretteBundle to upload the images on Amazon.
Sure, you would want to use the AWS SDK for PHP and then you will be able to access all the files in a given S3 drirectory. Then pass those to twig so you can render them.
S3 Usage Documentation
use Aws\S3\S3Client;
...
public function gallaryAction(){
$client = S3Client::factory(array(
'key' => '<aws access key>',
'secret' => '<aws secret key>'
));
$images = $client->getIterator('ListObjects', array(
'Bucket' => $bucket,
'Marker' => 'folder1/gallary/',
//I believe marker is what would be use to say only objects in this folder. Not 100% on that.
));
return $this->render('twig_template_name.html.twig',array('images'=> $images));
}
Then you would just use the images in your twig file to create the s3 link.

laravel development environment sqlite database does not exist

Trying to use sqlite in development environment. It seems to detect the environment correctly but when I try to migrate to development.sqlite I get exception thrown "database does not exist"
artisan command
php artisan migrate --env=development
bootstrap/start.php
$env = $app->detectEnvironment(array(
'development' => array('localhost'),
));
app/config/development/database.php
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/development.sqlite',
'prefix' => '',
)
)
);
As far as I know laravel is supposed to create the file if it does not exist but since it didn't I tried manually creating the file and still get the exception thrown.
UPDATE: Maybe something not right with the env because the same thing happens if I try ':memory' for the database.
UPDATE 2: I tried running the sample unit test but add to TestCase.php
/**
* Default preparation for each test
*
*/
public function setUp()
{
parent::setUp(); // Don't forget this!
$this->prepareForTests();
}
/**
* Creates the application.
*
* #return Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}
/**
* Migrates the database and set the mailer to 'pretend'.
* This will cause the tests to run quickly.
*
*/
private function prepareForTests()
{
Artisan::call('migrate');
Mail::pretend(true);
}
And this too gives the same exception though the testing env is already shipped with laravel. So I'll see if I can find any new issues on that.
Wow, typos and wrong paths.
Copying the sqlite array from config/database.php into config/development/database.php I forgot to change the path to the development.sqlite file from
__DIR__.'/../database/development.sqlite'
to
__DIR__.'/../../database/development.sqlite'
And for the in memory test it should have been
':memory:'
instead of
':memory'
I noticed that my database.php file had the following
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
I changed it to read the following, and it worked just fine.
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
One of the problem which I faced was I use "touch storage/database.sqlite" in terminal, so database is created in Storage folder instead of database folder.
in my config/database.php path is database_path('database.sqlite')
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
than I use command "php artisan migrate" which gave me error "Database (/Applications/MAMP/htdocs/FOLDER_NAME/database/database.sqlite) does
not exist."
so it's obvious database file is not in database folder as It was generated in Storage folder, so copy "database.sqlite" from storage folder or run command "touch database/database.sqlite"
Hope that helps.!!
Well, my answer is kinda outdated, but anyway. I faced the same problem, but with Laravel 5, I am using Windows 7 x64. First I manually created SQLite database called 'db' and placed it into storage directory, then fixed my .env file like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=oBxQMkpqbENPb07bLccw6Xv7opAiG3Jp
DB_HOST=localhost
DB_DATABASE='db'
DB_USERNAME=''
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null`
I thought it would fix my problems, but the command line keeps telling me that database doesn't exist. And then I just checked the path to db in my database.php file and this is why I put database file into storage directory. But nothing changed. And finally I checked db's extension and it was .db, not .sqlite as default extension you see in your sqlite block in database.php. So this is how I reconfigured sqlite piece:
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/db.db',
'prefix' => '',
],
And of course don't forget to set sqlite as default database in your database.php file. Good luck!
For me it was that path to database had to be '/var/www/html' + location to the database in your project. In my case database was stored in database/db.sqlite so DB_DATABASE='/var/www/html/database/db.sqlite'
I had the same error while running a GitHub action test workflow.
For me the solution was to define the relative path to the database archive into the workflow file:
on:
...
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
jobs:
laravel-tests:
...
I think that the previous answers reduce the importance of the config and most likely the developers wanted to get the database file like this:
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => database_path(env('DB_DATABASE', 'database').'.sqlite'), // <- like this
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
Tested on Laravel 9.x

Fatal error while installing symfony2 in autoload.php

I'm trying to install symfony for a week now and i have plenty of errors everytime !!!
i couldn't find a solution to this specific error :
Fatal error: Class 'Doctrine\Common\Annotations\AnnotationRegistry' not found in C:\wamp\www\Symfony\app\autoload.php on line 35
here's what i have in the autoload.php file :
$loader->register();AnnotationRegistry::registerLoader(function($class) use ($loader) {
$loader->loadClass($class);return class_exists($class, false);});
Any ideas please?
Make sure that you have registered Doctrine\Common namespace like this in autoload.php:
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
'Sensio' => __DIR__.'/../vendor/bundles',
'JMS' => __DIR__.'/../vendor/bundles',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
// more lines here...
));
It is important that Doctrine\Common namespaces is above Doctrine (look here - autoload.php from github).
Maybe you downloaded symfony without vendors? So this error occurs, because required files are missing.

Resources