[TYPO3-team-core-v5] RFC: ComponentFactory

Malte Jansen mail at maltejansen.de
Tue Sep 30 19:01:41 CEST 2008


Hi Robert,

Robert Lemke schrieb:
> Hi Malte,
> 
> Am 29.09.2008 um 21:55 schrieb Karsten Dambekalns:
> 
>> Malte Jansen wrote:
>>> IMO the ComponentFactory should also have a function
>>> isComponentRegistered(), so it's pretty easy to make your own
>>
>> Well, a factory creates things. Is checking about registered stuff in
>> it's domain? Quick, before Roberts reads this! ;)
> 
> Exactly: Factory = make things, Manager = manage things

That's true, but is clever to divide this so strictly?
Perhaps we could make an extended version of the factory...

So I have just extendend the normal factory. So I have access to the 
isComponentRegistered(). But sometimes the an extra class is to much.

Just for getting an idea.

class ComponentFactory extends F3::FLOW3::Component::Factory {
	public function getTokenComponentByElementType($elementType) {
		switch ($elementType) {
			case 'Interface':
				$elementType = 'IClass';
				break;
			case 'Abstract class':
				$elementType = 'AClass';
				break;
		}
		$componentName = 'F3::FLOW3CGL::DocComment::Elements::' . 
ucfirst($elementType) . 'Element';
		if (!$this->compoinentManager->isComponentRegistered($componentName)) {
			throw new 
F3::FLOW3CGL::DocComment::Exception::UnknownTagComponent('Component "' . 
$componentName . '" is not registered.', 1222723005);
		}
		return parent::getComponent($componentName);
	}
}

Will be in the repository in the next days. I have implemented the 
namespaces into the DocComment & the NamingConventions.

> 
> In our case the manager has a built-in registry, hence the is*Registered()
> method. You might even argue that "getComponent" is not really a nice
> name for a factory method, but hey ...

getComponent was just fine, until you mentioned it ;)
What about createComponent() ?

> 
> Anyway, Malte, I support your idea of adding some way to register
> custom factories, but not in this way.
> 
> I have something else in mind, some way that PHP supports this natively.
> I plan to write an RFC for the PHP devs and see if I can find someone
> with karma to propose that feature in the php-internals list.
> 

Sounds promising :D

Cheers,

Malte


More information about the TYPO3-team-core-v5 mailing list