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

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?

Related

Class 'Firebase\Jwt\Jwt' not found YII2

composer require firebase/php-jwt:^2.2
install is OK
So
use \Firebase\JWT\JWT;
$key = "example_key";
$payload = array(
"iss" => "http://example.org",
"aud" => "http://example.com",
"iat" => 1356999524,
"nbf" => 1357000000
);
$jwt = JWT::encode($payload, $key);
Error
Class 'Firebase\Jwt\Jwt' not found
Help me!!!
Detail Error
Dettaglio Errore
Thank You
The code in index.php doesn't look like code you wrote here. Try to use \Firebase\JWT\JWT; in index.php.
Also PHP namespaces are case sensitive, so make sure you wrote it correct or use IDE's autocomplete.

How to set Airbrake with drupal 8

I'm trying to use Airbrake with my drupal 8 project, I follow this GitHub page https://github.com/akalsey/airbrake-drupal. I create an account and install the Airbrake using Composer composer require airbrake/phpbrake. Then it says that I should copy this snippet into your PHP app
$notifier = new Airbrake\Notifier(array(
'projectId' => ****,
'projectKey' => '****'
));
Airbrake\Instance::set($notifier);
$handler = new Airbrake\ErrorHandler($notifier);
$handler->register();
But I don't know in which file I past it?
Any help?

How to run Drupal 8 functions from an external PHP file

Is there any way to execute Drupal 8 functions from an external PHP file.
You can include/call Drupal's bootstrap in your script and after that call Drupal's functions. Used that for D7, but didn't try for D8. However it should work:
https://drupal.stackexchange.com/questions/174474/bootstrap-from-external-script
And to copy code from that page:
define('DRUPAL_DIR', '/usr/share/nginx/html');
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
require_once DRUPAL_DIR . '/core/includes/database.inc';
require_once DRUPAL_DIR . '/core/includes/schema.inc';
// Specify relative path to the drupal root.
$autoloader = require_once DRUPAL_DIR . '/autoload.php';
$request = Request::createFromGlobals();
// Bootstrap drupal to different levels
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
$kernel->prepareLegacyRequest($request);
$em = $kernel->getContainer()->get('entity.manager');
$entity = $em->getStorage('node')->create(
array(
'type' => "article",
'title'=> "test entity",
'body' => "body body body",
));
$entity->save();
If you have Drush, you can run "drush scr [filename]" which will execute the file as well as bootstrap Drupal. I did a blog post about this - https://www.oliverdavi.es/blog/dont-bootstrap-drupal-use-drush.
I'd only use this for simple local test scripts though to test things out before moving the code into proper functions/classes/controllers/services etc.
You can run any php code either drupal or non-drupal using Devel and Kint module like this.[Use Devel and Kint module] like this
https://i.stack.imgur.com/RUKv6.png

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

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.

Symfony2: class MapClassLoader not found

I'm trying to use MapClassLoader in autoload.php but for some reason I keep getting errors saying
Class 'Symfony\Component\ClassLoader\MapClassLoader' not found in ...\autoload.php
autoload.php:
<?php
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\ClassLoader\MapClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
//some values
));
$mapLoader = new MapClassLoader(array(
//some values
));
$mapLoader->register();
I double checked and MapClassLoader.php does exist in Symfony\Component\ClassLoader
Any idea why is it happening? :/
autoload.php is a file that configures autoloading for classes so autoloading isn't available in it and you need to include any files manually:
require_once __DIR__.'/../vendor/symfony/src/Symfony/ClassLoader/MapClassLoader.php';
Why is UniversalClassLoader available without require? Because symfony uses bootstrap file for system files to reduce file loading overhead.

Resources