I have composer.json structure like this:
"psr-0": {
"DatabaseSeeder\\": "app/database/seeds/"
},
I have files in app/database/seeds (Files here can be created dynamically so solution with "classmap": ["app/database/seeds"] doesn't work here bcs I have to always dump-autoload before seeding:
- UserTableSeeder.php
- DatabaseSeeder.php
with structure like this:
# DatabaseSeeder.php
namespace DatabaseSeeder;
use Doctrine\ORM\EntityManager;
class DatabaseSeeder implements Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run(EntityManager $em)
{
$this->call('DatabaseSeeder\UserTableSeeder', $em);
}
private function call($class, $em)
{
$reflectionMethod = new \ReflectionMethod($class, 'run');
$reflectionMethod->invoke(new $class, $em);
}
After php composer.phar install and php composer.phar dump-autoload I cannot use in application for example in index.php
$object = new \DatabaseSeeder\DatabaseSeeder();
because I recieve error: Class DatabaseSeeder\DatabaseSeeder does not exist WHY ?? It should autoload class while initiating object.