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

  • ActiveRecord
  • ClassLoader
  • DcCompat
  • TemplateLoader
  • 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\Compatibility;
 14: 
 15: use DcGeneral\Data\ModelInterface;
 16: use DcGeneral\DC_General;
 17: use DcGeneral\EnvironmentInterface;
 18: use DcGeneral\Exception\DcGeneralException;
 19: use DcGeneral\Exception\DcGeneralRuntimeException;
 20: use DcGeneral\Factory\Event\PopulateEnvironmentEvent;
 21: 
 22: /**
 23:  * Class DcCompat
 24:  *
 25:  * Small compatibility layer for callbacks, that expect a "full featured" DC instance.
 26:  */
 27: class DcCompat extends DC_General
 28: {
 29:     /**
 30:      * The current model.
 31:      *
 32:      * @var ModelInterface
 33:      */
 34:     protected $model;
 35: 
 36:     /**
 37:      * Name of the property currently working on.
 38:      *
 39:      * @var string
 40:      */
 41:     protected $propertyName;
 42: 
 43:     /**
 44:      * Create a new instance.
 45:      *
 46:      * @param EnvironmentInterface $environment  The Dc instance to use for delegating.
 47:      *
 48:      * @param ModelInterface       $model        The model within scope.
 49:      *
 50:      * @param null                 $propertyName The name of the property within scope.
 51:      */
 52:     public function __construct(EnvironmentInterface $environment, ModelInterface $model, $propertyName = null)
 53:     {
 54:         $this->objEnvironment = $environment;
 55:         $this->model          = $model;
 56:         $this->propertyName   = $propertyName;
 57:     }
 58: 
 59:     /**
 60:      * Retrieve the current model.
 61:      *
 62:      * @return ModelInterface
 63:      */
 64:     public function getModel()
 65:     {
 66:         return $this->model;
 67:     }
 68: 
 69:     /**
 70:      * Retrieve the current property.
 71:      *
 72:      * @return string
 73:      */
 74:     public function getPropertyName()
 75:     {
 76:         return $this->propertyName;
 77:     }
 78: 
 79:     /**
 80:      * {@inheritdoc}
 81:      *
 82:      * @throws DcGeneralException This method is for internal use only.
 83:      */
 84:     public function handlePopulateEnvironment(PopulateEnvironmentEvent $event)
 85:     {
 86:         throw new DcGeneralException(__CLASS__ . '::handlePopulateEnvironment() is internal use only and must not be called');
 87:     }
 88: 
 89:     /**
 90:      * {@inheritdoc}
 91:      *
 92:      * @throws DcGeneralException This method is for internal use only.
 93:      */
 94:     protected function getTablenameCallback($strTable)
 95:     {
 96:         throw new DcGeneralException(__CLASS__ . '::getTablenameCallback() is internal use only and must not be called');
 97:     }
 98: 
 99:     /**
100:      * {@inheritdoc}
101:      *
102:      * @throws DcGeneralRuntimeException The magic setter is unsupported and has been deactivated.
103:      */
104:     public function __set($strKey, $varValue)
105:     {
106:         throw new DcGeneralRuntimeException('The magic setter is not supported anymore!');
107:     }
108: 
109:     /**
110:      * {@inheritdoc}
111:      */
112:     // @codingStandardsIgnoreStart - We know this method is very complex but we can not reduce the switch cases.
113:     public function __get($name)
114:     // @codingStandardsIgnoreEnd
115:     {
116:         switch ($name)
117:         {
118:             case 'id':
119:                 return $this->model->getId();
120: 
121:             case 'parentTable':
122:                 if ($this->getEnvironment()->getParentDataDefinition())
123:                 {
124:                     return $this->getEnvironment()->getParentDataDefinition()->getName();
125:                 }
126:                 return null;
127: 
128:             case 'childTable':
129:                 throw new DcGeneralRuntimeException('The magic property $dc->childTable is not supported yet!');
130: 
131:             case 'rootIds':
132:                 throw new DcGeneralRuntimeException('The magic property $dc->rootIds is not supported yet!');
133: 
134:             case 'createNewVersion':
135:                 throw new DcGeneralRuntimeException('The magic property $dc->createNewVersion is not supported yet!');
136: 
137:             case 'table':
138:                 return $this->getEnvironment()->getDataProvider()->getEmptyModel()->getProviderName();
139: 
140:             case 'value':
141:                 if ($this->propertyName && $this->getModel())
142:                 {
143:                     return $this->getModel()->getProperty($this->propertyName);
144:                 }
145:                 return null;
146: 
147:             case 'field':
148:                 return $this->propertyName;
149: 
150:             case 'inputName':
151:                 return $this->propertyName;
152: 
153:             case 'palette':
154:                 throw new DcGeneralRuntimeException('The magic property $dc->palette is not supported yet!');
155: 
156:             case 'activeRecord':
157:                 return new ActiveRecord($this->model);
158: 
159:             default:
160:         }
161: 
162:         throw new DcGeneralRuntimeException('The magic property ' . $name . ' is not supported (yet)!');
163:     }
164: 
165:     /**
166:      * {@inheritdoc}
167:      */
168:     public function getDCA()
169:     {
170:         // NOTE: This is the only part from legacy DC_General we can not retrieve via Environment.
171:         // It is usually passed via constructor call in DC_General but in 99.9% of all cases, this is the direct
172:         // mapping of the globals DCA.
173:         return $GLOBALS['TL_DCA'][$this->getEnvironment()->getParentDataDefinition()->getName()];
174:     }
175: }
176: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0