Doctrine2 using composer namespace error

2

Hello, I'm creating a file that serves as base class in Entities \ BaseTable.php as follows:

<?php namespace Entidades;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @MappedSuperclass
 */
class BaseTable
{
    /**
     * @Id @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

    /**
     * @Column(type="datetime")
     * @var datetime
     */
    protected $criado_em;

    public function __construct()
    {
        date_default_timezone_set('Australia/Melbourne');
        $this->criado_em = new DateTime(null, new DateTimeZone('America/Sao_Paulo'));
    }

    public function getId()
    {
        return $this->id;
    }
}
?>

The other file is a base extension, which is in Entities \ System \ Application.php as follows:

<?php namespace Entidades\Sistema;

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity @Table(name="sistema.aplicativos")
 */
class Aplicativo Extends \Entidades\BaseTable
{
    /**
     * @Column(type="string", nullable=false)
     * @var string
     */
    public $nome;

    /**
     * @Column(type="string", unique=true, nullable=false)
     * @var string
     */
    public $app_key;

    /**
     * @Column(type="string", unique=true, nullable=false)
     * @var string
     */
    public $esquema;

    public function addAplicativo($nome,$esquema)
    {
        $this->nome = $nome;
        $this->esquema = $esquema;
    }

    protected function newGuid()
    {
        if (function_exists('com_create_guid') === true)
        {
            return trim(com_create_guid(), '{}');
        }
        return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
    }

    public function __construct()
    {
        parent::__construct();
        $this->app_key = newGuid();
    }
}
?>

When you run the command "php vendor / doctrine / orm / bin / doctrine orm: schema-tool: create" with the command everything works fine, no problems, tables are created and etc ...

But when running a php like the example below:

<?php
require_once "bootstrap.php";

$novo = new Sistema\Aplicativo();
$novo->nome = 'Teste';
$novo->esquema = 'Teste';

$entityManager->persist($novo);
$entityManager->flush();

echo "Aplicativo com o ID " . $product->getId() . " criado com sucesso.\n";
?>

I get the following error in PHP:

Fatal error: Class 'Entidades\BaseTable' not found in APPPATH\Entidades\Sistema\Aplicativo.php on line 9
Call Stack
#   Time    Memory  Function    Location
1   0.0005  127704  {main}( )   ..\addAplicativo.php:0
2   0.0625  2090808 Composer\Autoload\ClassLoader->loadClass( ) ..\addAplicativo.php:0
3   0.0625  2090912 Composer\Autoload\includeFile( )    ..\ClassLoader.php:274
4   0.0632  2098568 include( 'D:\TRABALHO\Admin v3\Server\Entidades\Sistema\Aplicativo.php' )   ..\ClassLoader.php:382

As you can see the file of the Application.php is included, I can find it without problems, the problem is to get the extend of it ... I do not know why this is happening, but I can not correct it or pray, I looked for some examples similar on the internet and for help on various websites, but nothing that relates to this, I think I'm doing some stupid grotesque ... grateful for the attention.

    
asked by anonymous 01.09.2014 / 22:19

1 answer

2

SOLUTION

The problem was with the autoload ...

I made a foolish mistake, the solution was to put psr-4 instead of psr-0 in autoload of composer, after changing the psr-0 to psr-4 it worked everything 100% m follows the solution ...

"autoload": {
    "psr-4": {
        "": "Entidades/",
        "Entidades\": "Entidades/",
        "Entidades\Sistema\": "Entidades/Sistema/"
    }
}

Thank you for your personal attention.

    
02.09.2014 / 05:18