CRUDlex\ServiceProvider

class ServiceProvider

The ServiceProvider setups and initializes the whole CRUD system. After adding it to your Silex-setup, it offers access to {@see AbstractData} instances, one for each defined entity off the CRUD YAML file.

property datas

protected

Holds the {@see AbstractData} instances.

property manageI18n

protected

Holds whether we manage the i18n.

readYaml($fileName)

Reads and returns the contents of the given Yaml file. If it goes wrong, it throws an exception.

Parameters:
  • $fileName (string) – the file to read
Returns:

array the file contents

initMissingServiceProviders(Container $app)

Initializes needed but yet missing service providers.

Parameters:
  • $app (Container) – the application container
initLocales(Container $app)

Initializes the available locales.

Parameters:
  • $app (Container) – the application container
Returns:

array the available locales

initChildren()

Initializes the children of the data entries.

getLocaleLabels($locales, $crud)

Gets a map with localized entity labels from the CRUD YML.

Parameters:
  • $locales (array) – the available locales
  • $crud (array) – the CRUD entity map
Returns:

array the map with localized entity labels

configureDefinition(EntityDefinition $definition, $crud)

Configures the EntityDefinition according to the given CRUD entity map.

Parameters:
  • $definition (EntityDefinition) – the definition to configure
  • $crud (array) – the CRUD entity map
createDefinition(Container $app, $locales, $crud, $name)

Creates and setups an EntityDefinition instance.

Parameters:
  • $app (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
Returns:

EntityDefinition the EntityDefinition good to go

validateEntityDefinition(Container $app, $entityDefinition)

Validates the parsed entity definition.

Parameters:
  • $app (Container) – the application container
  • $entityDefinition (array) – the entity definition to validate
init(DataFactoryInterface $dataFactory, $crudFile, FileProcessorInterface $fileProcessor, $manageI18n, Container $app)

Initializes the instance.

Parameters:
  • $dataFactory (DataFactoryInterface) – the factory to create the concrete AbstractData instances
  • $crudFile (string) – the CRUD YAML file to parse
  • $fileProcessor (FileProcessorInterface) – the file processor used for file fields
  • $manageI18n (boolean) – holds whether we manage the i18n
  • $app (Container) – the application container
register(Container $app)

Implements ServiceProviderInterface::register() registering $app[‘crud’]. $app[‘crud’] contains an instance of the ServiceProvider afterwards.

Parameters:
  • $app (Container) – the Container instance of the Silex application
getData($name)

Getter for the {@see AbstractData} instances.

Parameters:
  • $name (string) – the entity name of the desired Data instance
Returns:

AbstractData the AbstractData instance or null on invalid name

getEntities()

Getter for all available entity names.

Returns:string[] a list of all available entity names
getTemplate(Container $app, $section, $action, $entity)

Determines the Twig template to use for the given parameters depending on the existance of certain keys in the Container $app in this order:

crud.$section.$action.$entity crud.$section.$action crud.$section

If nothing exists, this string is returned: “@crud/<action>.twig”

Parameters:
  • $app (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
Returns:

string the best fitting template

isManagingI18n()

Gets whether CRUDlex manages the i18n system.

Returns:boolean true if CRUDlex manages the i18n system
setLocale($locale)

Sets the locale to be used.

Parameters:
  • $locale (string) – the locale to be used.
getLocales()

Gets the available locales.

Returns:array the available locales