Esempio n. 1
0
 /**
  * Возвращает обязательное поле коллекции.
  * @param $fieldName
  * @throws NonexistentEntityException если поле не существует
  * @return IField
  */
 protected function getRequiredField($fieldName)
 {
     if (!$this->metadata->getFieldExists($fieldName)) {
         throw new NonexistentEntityException($this->translate('Collection "{collection}" does not contain required field "{name}".', ['collection' => $this->name, 'name' => $fieldName]));
     }
     return $this->metadata->getField($fieldName);
 }
Esempio n. 2
0
 /**
  * Конструктор.
  * @param string $name имя
  * @param array $config конфигурация
  * @param IMetadata $metadata метаданные, к которым относится тип
  * @throws UnexpectedValueException в случае неверно заданной конфигурации
  */
 public function __construct($name, array $config, IMetadata $metadata)
 {
     $this->name = $name;
     $this->metadata = $metadata;
     if (isset($config['objectClass'])) {
         $this->objectClassName = strval($config['objectClass']);
     } else {
         if ($parentType = $metadata->getParentType($this->name)) {
             $this->objectClassName = $parentType->getObjectClass();
         }
     }
     if ($parentType = $metadata->getParentType($this->name)) {
         $this->fields = $parentType->getFields();
     }
     if (isset($config['fields'])) {
         if (!is_array($config['fields'])) {
             throw new UnexpectedValueException($this->translate('Type fields configuration should be an array.'));
         }
         foreach ($config['fields'] as $fieldName => $options) {
             $this->fields[$fieldName] = $metadata->getField($fieldName);
         }
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function fields(array $fieldNames = [])
 {
     foreach ($fieldNames as $fieldName) {
         if ($this->metadata->getFieldExists($fieldName)) {
             $field = $this->metadata->getField($fieldName);
             $this->fields[$fieldName] = $field;
         } else {
             throw new NonexistentEntityException($this->translate('Cannot select objects. Field "{name}" does not exist.', ["name" => $fieldName]));
         }
     }
     return $this;
 }