PHP Class CRUDlex\ServiceProvider

After adding it to your Silex-setup, it offers access to {@see \AbstractData} instances, one for each defined entity off the CRUD YAML file.
Inheritance: implements Pimple\ServiceProviderInterface
ファイルを表示 Open project: philiplb/crudlex Class Usage Examples

Protected Properties

Property Type Description
$datas Holds the {@see AbstractData} instances.
$manageI18n Holds whether we manage the i18n.

Public Methods

Method Description
getData ( string $name ) : AbstractData Getter for the {@see AbstractData} instances.
getEntities ( ) : string[] Getter for all available entity names.
getLocales ( ) : array Gets the available locales.
getTemplate ( Pimple\Container $app, string $section, string $action, string $entity ) : string Determines the Twig template to use for the given parameters depending on the existance of certain keys in the Container $app in this order:
init ( crudlex\DataFactoryInterface $dataFactory, string $crudFile, crudlex\FileProcessorInterface $fileProcessor, boolean $manageI18n, Pimple\Container $app ) Initializes the instance.
isManagingI18n ( ) : boolean Gets whether CRUDlex manages the i18n system.
register ( Pimple\Container $app ) Implements ServiceProviderInterface::register() registering $app['crud'].
setLocale ( string $locale ) Sets the locale to be used.

Protected Methods

Method Description
configureDefinition ( EntityDefinition $definition, array $crud ) Configures the EntityDefinition according to the given CRUD entity map.
createDefinition ( Pimple\Container $app, array $locales, array $crud, string $name ) : EntityDefinition Creates and setups an EntityDefinition instance.
getLocaleLabels ( array $locales, array $crud ) : array Gets a map with localized entity labels from the CRUD YML.
initChildren ( ) Initializes the children of the data entries.
initLocales ( Pimple\Container $app ) : array Initializes the available locales.
initMissingServiceProviders ( Pimple\Container $app ) Initializes needed but yet missing service providers.
readYaml ( string $fileName ) : array Reads and returns the contents of the given Yaml file. If it goes wrong, it throws an exception.
validateEntityDefinition ( Pimple\Container $app, array $entityDefinition ) Validates the parsed entity definition.

Method Details

configureDefinition() protected method

Configures the EntityDefinition according to the given CRUD entity map.
protected configureDefinition ( EntityDefinition $definition, array $crud )
$definition EntityDefinition the definition to configure
$crud array the CRUD entity map

createDefinition() protected method

Creates and setups an EntityDefinition instance.
protected createDefinition ( Pimple\Container $app, array $locales, array $crud, string $name ) : EntityDefinition
$app Pimple\Container the application container
$locales array the available locales
$crud array the parsed YAML of a CRUD entity
$name string the name of the entity
return EntityDefinition the EntityDefinition good to go

getData() public method

Getter for the {@see AbstractData} instances.
public getData ( string $name ) : AbstractData
$name string the entity name of the desired Data instance
return AbstractData the AbstractData instance or null on invalid name

getEntities() public method

Getter for all available entity names.
public getEntities ( ) : string[]
return string[] a list of all available entity names

getLocaleLabels() protected method

Gets a map with localized entity labels from the CRUD YML.
protected getLocaleLabels ( array $locales, array $crud ) : array
$locales array the available locales
$crud array the CRUD entity map
return array the map with localized entity labels

getLocales() public method

Gets the available locales.
public getLocales ( ) : array
return array the available locales

getTemplate() public method

crud.$section.$action.$entity crud.$section.$action crud.$section If nothing exists, this string is returned: "@crud/.twig"
public getTemplate ( Pimple\Container $app, string $section, string $action, string $entity ) : string
$app Pimple\Container the Silex application
$section string the section of the template, either "layout" or "template"
$action string the current calling action like "create" or "show"
$entity string the current calling entity
return string the best fitting template

init() public method

Initializes the instance.
public init ( crudlex\DataFactoryInterface $dataFactory, string $crudFile, crudlex\FileProcessorInterface $fileProcessor, boolean $manageI18n, Pimple\Container $app )
$dataFactory crudlex\DataFactoryInterface the factory to create the concrete AbstractData instances
$crudFile string the CRUD YAML file to parse
$fileProcessor crudlex\FileProcessorInterface the file processor used for file fields
$manageI18n boolean holds whether we manage the i18n
$app Pimple\Container the application container

initChildren() protected method

Initializes the children of the data entries.
protected initChildren ( )

initLocales() protected method

Initializes the available locales.
protected initLocales ( Pimple\Container $app ) : array
$app Pimple\Container the application container
return array the available locales

initMissingServiceProviders() protected method

Initializes needed but yet missing service providers.
protected initMissingServiceProviders ( Pimple\Container $app )
$app Pimple\Container the application container

isManagingI18n() public method

Gets whether CRUDlex manages the i18n system.
public isManagingI18n ( ) : boolean
return boolean true if CRUDlex manages the i18n system

readYaml() protected method

Reads and returns the contents of the given Yaml file. If it goes wrong, it throws an exception.
protected readYaml ( string $fileName ) : array
$fileName string the file to read
return array the file contents

register() public method

$app['crud'] contains an instance of the ServiceProvider afterwards.
public register ( Pimple\Container $app )
$app Pimple\Container the Container instance of the Silex application

setLocale() public method

Sets the locale to be used.
public setLocale ( string $locale )
$locale string the locale to be used.

validateEntityDefinition() protected method

Validates the parsed entity definition.
protected validateEntityDefinition ( Pimple\Container $app, array $entityDefinition )
$app Pimple\Container the application container
$entityDefinition array the entity definition to validate

Property Details

$datas protected_oe property

Holds the {@see AbstractData} instances.
protected $datas

$manageI18n protected_oe property

Holds whether we manage the i18n.
protected $manageI18n