Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • BackendViewPopulator
  • DataProviderPopulator
  • ExtendedLegacyDcaPopulator
  • HardCodedPopulator
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
 1: <?php
 2: /**
 3:  * PHP version 5
 4:  * @package    generalDriver
 5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
 6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
 7:  * @author     Tristan Lins <tristan.lins@bit3.de>
 8:  * @copyright  The MetaModels team.
 9:  * @license    LGPL.
10:  * @filesource
11:  */
12: 
13: namespace DcGeneral\Contao\Dca\Populator;
14: 
15: use DcGeneral\Contao\Dca\ContaoDataProviderInformation;
16: use DcGeneral\Data\DataProviderInterface;
17: use DcGeneral\EnvironmentInterface;
18: use DcGeneral\EnvironmentPopulator\AbstractEventDrivenEnvironmentPopulator;
19: use DcGeneral\Exception\DcGeneralRuntimeException;
20: 
21: /**
22:  * Class DataProviderPopulator.
23:  *
24:  * This class reacts to the PopulateEnvironmentEvent and populates the environment with all data providers implementing
25:  * the interface ContaoDataProviderInformation.
26:  *
27:  * @package DcGeneral\Contao\Dca\Populator
28:  */
29: class DataProviderPopulator extends AbstractEventDrivenEnvironmentPopulator
30: {
31:     const PRIORITY = 100;
32: 
33:     /**
34:      * Instantiates and adds the data providers implementing ContaoDataProviderInformation to the environment.
35:      *
36:      * @param EnvironmentInterface $environment The environment to populate.
37:      *
38:      * @return void
39:      *
40:      * @throws DcGeneralRuntimeException When a data provider has already been added to the environment.
41:      */
42:     public function populate(EnvironmentInterface $environment)
43:     {
44:         $definition = $environment->getDataDefinition();
45: 
46:         foreach ($definition->getDataProviderDefinition() as $dataProviderInformation)
47:         {
48:             if ($dataProviderInformation instanceof ContaoDataProviderInformation)
49:             {
50:                 if ($environment->hasDataProvider($dataProviderInformation->getName()))
51:                 {
52:                     throw new DcGeneralRuntimeException(sprintf(
53:                         'Data provider %s already added to environment.',
54:                         $dataProviderInformation->getName()
55:                     ));
56:                 }
57: 
58:                 $providerClass = new \ReflectionClass($dataProviderInformation->getClassName());
59: 
60:                 /** @var DataProviderInterface $dataProvider */
61:                 $dataProvider = $providerClass->newInstance();
62:                 if ($initializationData = $dataProviderInformation->getInitializationData())
63:                 {
64:                     $dataProvider->setBaseConfig($initializationData);
65:                 }
66: 
67:                 $environment->addDataProvider($dataProviderInformation->getName(), $dataProvider);
68:             }
69:         }
70:     }
71: }
72: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0