zendframework / zend-servicemanager

ServiceManager component from Zend Framework
BSD 3-Clause "New" or "Revised" License
188 stars 89 forks source link

Factories created by generate-factory-for-class have fully-qualified namespace for classes pulled from the container #172

Open settermjd opened 7 years ago

settermjd commented 7 years ago

@weierophinney, here is the issue, as requested.

As I was researching generate-factory-for-class today to create a tutorial on it, I noticed that while most classes referenced in the factory classes it generates were relative, with their fully qualified namespaces included via use statements, classes which were pulled from the container were not.

Here's an example of what I mean:

<?php

namespace App\ServiceManager\TableGateway;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use App\ServiceManager\TableGateway\JournalTable;

class JournalTableFactory implements FactoryInterface
{
    /**
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param null|array $options
     * @return JournalTable
     */
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        // Note that \Zend\Db\TableGateway\TableGateway is fully qualified
        return new JournalTable(
            $container->get(\Zend\Db\TableGateway\TableGateway::class)
        );
    }
}

I'm not sure if there's something that I've missed; but to me, for consistency's sake if nothing else, it makes sense to have classes retrieved from the container be relative as well.

settermjd commented 7 years ago

fwiw, great job on the class. The generated classes are excellently formatted, with proper docblock comments, etc. Thanks for making this happen.

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-servicemanager; a new issue has been opened at https://github.com/laminas/laminas-servicemanager/issues/20.