CRUDlex\ServiceProvider

class ServiceProvider

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

property datas

protected array

Holds the data instances.

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($crudFileCachingDirectory, Container $app)

Initializes the instance.

Parameters:
  • $crudFileCachingDirectory (string|null) – the writable directory to store the CRUD YAML file cache
  • $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
boot(Application $app)

Initializes the crud service right after boot.

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

Getter for the 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
getEntitiesNavBar()

Getter for the entities for the navigation bar.

Returns:string[] a list of all available entity names with their group
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

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