MicroiFramework Slim / ORM Doctrine - Some classes are missing in the vendor folder,

93 views Asked by At

Good Morning,

Firstly, I want to inform you that English is not my first language, and I apologize for my imperfect English. I'm also new to use networks . I installed Slim and I test it with a crud with success

I want now to install with slim the Doctrine ORM, like this: slimframework

In the bootstrap.php, there are underlines ("Undefined type").

bootstrap.php

here the accessible code:

<?php

namespace App\config;
// bootstrap.php

use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use UMA\DIC\Container;

$container = new Container(require __DIR__ . '/settings.php');

$container->set(EntityManager::class, static function (Container $c): EntityManager {
    /** @var array $settings */
    $settings = $c->get('settings');

    // Use the ArrayAdapter or the FilesystemAdapter depending on the value of the 'dev_mode' setting
    // You can substitute the FilesystemAdapter for any other cache you prefer from the symfony/cache library
    $cache = $settings['doctrine']['dev_mode'] ?
        DoctrineProvider::wrap(new ArrayAdapter()) :
        DoctrineProvider::wrap(new FilesystemAdapter(directory: $settings['doctrine']['cache_dir']));

    $config = Setup::createAttributeMetadataConfiguration(
        $settings['doctrine']['metadata_dirs'],
        $settings['doctrine']['dev_mode'],
        null,
        $cache
    );

    return EntityManager::create($settings['doctrine']['connection'], $config);
});

return $container;


($routes = require __DIR__ . '/routes.php')($app);
  • The classes importations seem good (no underline). But most of the folders and classes of the code doesn't exist in the folder "vendor")

  • I have tried to delete the folder vendor and the composer.lock folder:

rm -rf vendor/ composer.lock

then

require composer
  • I have reinstalled with no success.

  • The problem is the same with phpStorm.

Thank's for your help.

1

There are 1 answers

4
glitchcl On

Since there are lot of classes that are not available (and the slim documentation is not updated according to the last version of packages), you will have to adapt the code yourself. For example, DoctrineProvider class was abandoned after "doctrine/orm": "^2.19". So you will have to change your bootstrap file like this:

<?php

// bootstrap.php

use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use UMA\DIC\Container;

require_once __DIR__ . '/vendor/autoload.php';

$container = new Container(require __DIR__ . '/settings.php');

$container->set(EntityManager::class, static function (Container $c): EntityManager {
    /** @var array $settings */
    $settings = $c->get('settings');

    // Use the ArrayAdapter or the FilesystemAdapter depending on the value of the 'dev_mode' setting
    // You can substitute the FilesystemAdapter for any other cache you prefer from the symfony/cache library
    $cache = $settings['doctrine']['dev_mode'] ?
        new ArrayAdapter() :
        new FilesystemAdapter(directory: $settings['doctrine']['cache_dir']);

    $config = ORMSetup::createAttributeMetadataConfiguration(
        $settings['doctrine']['metadata_dirs'],
        $settings['doctrine']['dev_mode'],
        null,
        $cache
    );

    $connection = DriverManager::getConnection($settings['doctrine']['connection']);
    return new EntityManager($connection, $config);
});

return $container;

Enough talking, i created a basic example php slim basic from Github Codespaces with php 8.2