PHP Class Bravo3\Orm\Services\EntityLocator

Show file Open project: bravo3/orm Class Usage Examples

Protected Properties

Property Type Description
$entity_manager EntityManager
$normaliser callable

Public Methods

Method Description
__construct ( EntityManager $entity_manager = null )
getEntityManager ( ) : EntityManager | null Get the entity manager currently used for validation
getNormaliser ( ) : callable Get class normaliser
locateEntities ( string $dir, string $namespace, string $regex = '/^.+\.php$/i' ) : string[] Gather all entities in a given directory
setEntityManager ( EntityManager $entity_manager = null ) Set the entity manager, if null no entity validation will occur
setNormaliser ( callable $normaliser ) Set class normaliser

Method Details

__construct() public method

public __construct ( EntityManager $entity_manager = null )
$entity_manager EntityManager

getEntityManager() public method

Get the entity manager currently used for validation
public getEntityManager ( ) : EntityManager | null
return EntityManager | null

getNormaliser() public method

By default this will return a callback that will simply strip the file extension from the input. If you have a more complex filename structure you can account for it using the #setNormaliser() function (see docblock). However be aware that you're probably not PSR compliant if you need to do this.
public getNormaliser ( ) : callable
return callable

locateEntities() public method

Assumes PSR-0/4 compliant entity class names, and an appropriate auto-loader is installed.
public locateEntities ( string $dir, string $namespace, string $regex = '/^.+\.php$/i' ) : string[]
$dir string Directory to scan
$namespace string PSR base namespace for the directory
$regex string Filter for file matching
return string[]

setEntityManager() public method

Set the entity manager, if null no entity validation will occur
public setEntityManager ( EntityManager $entity_manager = null )
$entity_manager EntityManager

setNormaliser() public method

This must be a callback that takes 1 argument and will return a string. Its purpose is to convert file names into class names, for example, "MyEntity.php" should return "MyEntity". It will only ever operate on the final segment of a namespace.
public setNormaliser ( callable $normaliser )
$normaliser callable

Property Details

$entity_manager protected property

protected EntityManager,Bravo3\Orm\Services $entity_manager
return EntityManager

$normaliser protected property

protected callable $normaliser
return callable