Doubt about the doctrine \ dbal project structure

1

I read the Documentation the only thing I did not understand was as is the structure of it.

I explain:

My file composer.json in the project root

{
 "require": {
    "doctrine/dbal": "2.4.*"
  }
}

When you run the command:

php composer.phar install

It drops dependencies by generating the vendor folder. But there are many files that according to the documentation are unnecessary. See my project image:

I want to understand the structure of this project from what I've been reading the only important part is \lib\DBAL the others do not need. That's right. And in relation to the project wanted to use like that. Have a \class folder and put the files of both doctrine\dbal and bootstrap.php and crud classes (it would be crud.php with the CRUD functions and a require(bootstrap.php) Bootstrap is where the connection to the Bank). And out of the class folder (project root) make the functions calls on my pages. This is how I do it in a normal project.

I am asking this question because I have not found anything on the internet that speaks about this subject or the documentation. I'm starting in doctrine\dbal , sorry if I'm being incomprehensible.

    
asked by anonymous 05.09.2014 / 22:54

1 answer

2

You're doing it almost the right way.

When you install a dependency on your project, it often does not have other dependencies. In the case of doctrine/dbal , as you can see in the packagist (or directly at repository ), one of its dependencies is the doctrine/common package.

Doctrine is already a library that has several years of maturity, so it is rather obvious that it does not consist of just one or a few files. However, with dependency management becoming easier, this should not be a problem since the dependencies are in the vendor/ folder and your code is at the root of the project (in general, the vendor/ folder should not be committed , and yes, its files composer.json and composer.lock ).

I made a small project here, and the structure looks like this:

composer.json:

{
    "name": "root/teste-dbal",
    "require": {
        "doctrine/dbal": "2.5.x-dev"
    }
}

autoload.php:

<?php

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

bootstrap.php

<?php

require_once(__DIR__ . '/autoload.php');

// prepara a conexao
$config = new \Doctrine\DBAL\Configuration();
$connectionParameters = [
    'dbname'      => 'cms',
    'user'        => 'root',
    'password'    => '',
    'host'        => 'localhost',
    'driver'      => 'pdo_mysql',
    'unix_socket' => '/tmp/mysql.sock'
];
$connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParameters, $config);

crud.php

<?php

require_once(__DIR__ . '/bootstrap.php');

// executa a query
$sql = "SELECT * FROM users";
$statement = $connection->prepare($sql);
$statement->execute();
$users = $statement->fetchAll();

If you have any further questions, just let me know. :)

    
11.09.2014 / 18:19