Check and create table if not exists

@param ContainerInterface $container ContainerInterface Container
@param                    $className String  Name of the ORM class
@param bool               $force     bool    Force update table
184609
public static function checkAndCreateTableByEntityName(ContainerInterface $container, $className, $force = false)
    {
        /** @var Registry $doctrine */
        /** @var Connection $connection */
        /** @var ClassMetadata $classMetadata */
        $doctrine      = $container->get('doctrine');
        $manager       = $doctrine->getManager();
        $schemaTool    = new SchemaTool($doctrine->getManager());
        $connection    = $doctrine->getConnection();
        $schemaManager = $connection->getSchemaManager();
        $classMetadata = $manager->getClassMetadata($className);

        if ($force || !$schemaManager->tablesExist($classMetadata->getTableName())) {

            if ($schemaManager instanceof SqliteSchemaManager) {

                $columns     = array();
                $identifiers = $classMetadata->getIdentifierColumnNames();
                foreach ($classMetadata->getFieldNames() as $fieldName) {
                    $fieldMapping = $classMetadata->getFieldMapping($fieldName);
                    $columnSql    = $fieldMapping["fieldName"];
                    switch ($fieldMapping["type"]) {
                        case 'integer':
                            $columnSql .= " INTEGER ";
                            break;

                        case 'real':
                        case 'double':
                        case 'float':
                            $columnSql .= " REAL ";
                            break;

                        case 'datetime':
                        case 'date':
                        case 'boolean':
                            $columnSql .= " INTEGER ";
                            break;

                        case 'blob':
                        case 'file':
                            $columnSql .= " BLOB ";
                            break;

                        default:
                            $columnSql .= " TEXT ";
                    }

                    // PRIMARY KEY
                    in_array($fieldName, $identifiers) && $columnSql .= "PRIMARY KEY ";
                    $columnSql .= $fieldMapping["nullable"] ? "NULL " : "NOT NULL ";
                    $columns[] = $columnSql;
                }
                $sql       = 'CREATE TABLE IF NOT EXISTS ' . $classMetadata->getTableName() . '( ' . implode(",\n", $columns) . ')';
                $statement = $connection->query($sql);
            } else {
                $schemaTool->updateSchema(array($classMetadata), true);
            }
        }
    }
181388
public function migrate(ContainerInterface $container): void
    {
        foreach ($this->getMigrations($container) as $class) {
            assert(is_string($class));
            $this->getIO()->writeInfo("Starting migration for `$class`..." . PHP_EOL, IoInterface::VERBOSITY_VERBOSE);
            if (($migration = $this->createMigration($class, $container)) !== null) {
                $migration->init($container)->migrate();
                $this->getIO()->writeInfo("Migration finished for `$class`." . PHP_EOL, IoInterface::VERBOSITY_NORMAL);
            }
        }
    }
200717
public function addDataSource($interfaceName, $driver, $className)
    {
        if (!isset($this->dataSources[$interfaceName]) || !is_array($this->dataSources[$interfaceName])) {
            $this->dataSources[$interfaceName] = array();
        }
        
        $this->dataSources[$interfaceName][$driver] = $className;
        $this->saveDataSources();
        
        return true;
    }
530108
public function create(string $className)
    {
        if (!class_exists($className)) {
            $classFileName = $this->fileNameforClass($className);
            $this->createFile($classFileName, $className, 'class.tmpl');
            $this->console->writeLine(
                    'Class ' . $className . ' created at ' . $classFileName
            );
        } else {
            $this->console->writeLine(
                    'Class ' . $className
                    . ' already exists, skipped creating the class'
            );
        }
    }
1076970
public function build(ContainerInterface $container, BuildDataDefinitionEvent $event)
    {
        if (!$this->loadDca($container->getName(), $this->getDispatcher())) {
            return;
        }

        $this->parseCallbacks($container, $this->getDispatcher());
        $this->parseBasicDefinition($container);
        $this->parseDataProvider($container);
        $this->parseRootEntries($container);
        $this->parseParentChildConditions($container);
        $this->parseBackendView($container);
        $this->parsePalettes($container);
        $this->parseProperties($container);
        $this->parseOderPropertyInPalette($container);
    }
54989
public function canCreate(string $className): bool
    {
        return !empty($this->entityManager->getClassMetadata($className)->associationMappings);
    }
323359
public function documentExists(TransferInterface $transfer, $containerName)
    {
        return $this->getFactory()
            ->createPdfDocumentManager()
            ->documentExists($transfer, $containerName);
    }
91017
public function canCreate(\Interop\Container\ContainerInterface $container, $requestedName)
    {
        $this->getConfig($container, $requestedName);
        return isset($this->dependencies[$requestedName]);
    }
741379
public static function validateUser(ContainerInterface $container, string $userName, string $password)
    {
        /** @var Connection $connection */
        $connection = $container->get(Connection::class);

        $query = $connection->createQueryBuilder();
        $query
            ->select([User::FIELD_ID, User::FIELD_EMAIL, User::FIELD_PASSWORD_HASH])
            ->from(User::TABLE_NAME)
            ->where(User::FIELD_EMAIL . '=' . $query->createPositionalParameter($userName))
            ->setMaxResults(1);
        $user = $query->execute()->fetch(PDO::FETCH_ASSOC);
        if ($user === false) {
            return null;
        }

        /** @var HasherInterface $hasher */
        $hasher = $container->get(HasherInterface::class);
        if ($hasher->verify($password, $user[User::FIELD_PASSWORD_HASH]) === false) {
            return null;
        }

        return (int)$user[User::FIELD_ID];
    }
1271601
public function process(ContainerBuilder $container)
    {
        $this->processDriverPass($container);
        $this->processDriverElementPass($container);
        $this->processEventSubscriberPass($container);
        $this->processClassGenerator($container);

        $this->setPageObjectNamespaces($container);
        $this->injectSiteUrlIntoPageObjects($container);
    }
1037564
public function delete(Model\RowInterface $row, $force = false)
    {
        $container = $row->getContainer();

        // Skip checks if forced
        if (!$force) {
            // Don't remove container's only row or named row
            if ($row->isAlone() || $row->isNamed()) {
                throw new InvalidOperationException(
                    "The row can't be removed because it is named or the parent container does not have enough children."
                );
            }

            // Don't remove standalone row
            if (null === $container) {
                throw new InvalidOperationException(
                    "The row does not belong to a container and therefore can't be removed."
                );
            }
        }

        $container->removeRow($row);

        $this->editor
            ->getContainerManager()
            ->fixRowsPositions($container);

        return $row;
    }
641705
public static function batchInsert(string $className, array $rows): ResultInterface
    {
        $instance = self::getInstance($className);

        return Query::table($className)->selectInstance($instance)->batchInsert($rows);
    }
643925
public function create($id, ContainerInterface $container)
    {
        if (isset($this->registeredList['services'][$id])) {
            $data = $this->createService($id, $container);
        } elseif (isset($this->registeredList['params'][$id])) {
            $data = $this->registeredList['params'][$id];
        } else {
            $data = null;
        }

        return $data;
    }
805961
public function addResource($name, $className)
    {
        $ref = new \ReflectionClass($className);
        try {
            $ref->implementsInterface(ResourceInterface::class);
        } catch (\ReflectionException $e) {
            throw new \InvalidArgumentException(sprintf('This resource "%s" does not implements ResourceInterface.', $name));
        }

        $this->resources[$name] = $className;
    }
552395
public function canCreate(ContainerInterface $container, $requestedName)
    {
        $config = $this->getConfig($container);

        return isset($config[$requestedName]);
    }
457491
protected static function createClassBinding($container, $binding)
    {
        return function ($value, $route) use ($container, $binding) {
            // If the binding has an @ sign, we will assume it's being used to delimit
            // the class name from the bind method name. This allows for bindings
            // to run multiple bind methods in a single class for convenience.
            [$class, $method] = Str::parseCallback($binding, 'bind');

            $callable = [$container->make($class), $method];

            return call_user_func($callable, $value, $route);
        };
    }
313259
public function process(ContainerBuilder $container)
    {
        $commands = $container->findTaggedServiceIds(
            'cli.command'
        );

        /** @var Application $application */
        $application = $container->get('application');

        foreach (array_keys($commands) as $id) {
            /** @var Command $command */
            $command = $container->get($id);

            if ($command instanceof ConditionalUseInterface) {
                /** @var ConditionalUseInterface $command */
                if (true !== $command->isUsable()) {
                    continue;
                }
            }

            $application->add($command);
        }
    }