Skip to content

Instantly share code, notes, and snippets.

@dmitrybubyakin
Last active November 12, 2016 09:10
Show Gist options
  • Save dmitrybubyakin/d5c4d2cca1b7fb30f39bfd0a670a75e9 to your computer and use it in GitHub Desktop.
Save dmitrybubyakin/d5c4d2cca1b7fb30f39bfd0a670a75e9 to your computer and use it in GitHub Desktop.

#Для ZF2, ZF3 разработчиков, использование ClassName::class В конфигах модулей, да и не только, часто приходится писать что-то вроде

//...
'controllers'  => [
	'factories' => [
		'Controller\IndexController' => 'Controller\IndexControllerFactory',
		],
    ],
//...
'validators' => [
	[
	    'name'    => 'EmailAddress',
	    'options' => [
        //...
	    ],
	],
],
//...
'routes' => [
	'test' => [
		'type' => 'literal',
		//...
	],
],

Начиная с php 5.5 мы можем получить имя класса используя ::class и можем код переписать следующим образом

//...
'controllers'  => [
	'factories' => [
		Controller\IndexController::class => Controller\IndexControllerFactory::class,
	],
],
//...
'validators' => [
	[
	    'name'    => \Zend\Validator\EmailAddress::class,
	    'options' => [
        //...
	    ],
	],
],
//...
'routes' => [
	'test' => [
		'type' => Literal::class,
		//...
	],
],

Плюсы такого подхода:

  • удобнее рефакторить
  • не нужно лезть в древо проекта и искать нужный класс, можно просто по нему сразу перейти
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment