Инициализирует элемент формы с помощью аннотаций.
@param IFormEntity $entity элемент
@param array $config конфигурация
328771
protected function initEntity(IFormEntity $entity, array $config)
    {
        foreach ($config as $name => $value) {
            $this->createAnnotation($name, $value)
                ->transform($entity);
        }
    }
650323
protected function _emailVerification(EntityInterface &$entity, $options) {
		if ($options['emailVerification'] === true) {
			$entity->set($this->_field('emailToken'), $this->generateToken($options['tokenLength']));
			if ($options['verificationExpirationTime'] !== false) {
				$entity->set($this->_field('emailTokenExpires'), $this->expirationTime($options['verificationExpirationTime']));
			}
			$entity->set($this->_field('emailVerified'), false);
		} else {
			$entity->set($this->_field('emailVerified'), true);
		}
	}
883583
public function setIdentifier($entity, array $id) : void
    {
        foreach ($id as $idField => $idValue) {
            $property = $this->class->getProperty($idField);

            $property->setValue($entity, $idValue);
        }
    }
859114
protected function _afterEntityInstantiate(AnConfig $config)
    {
        $config->append(array(
          'data' => array(
              'orderId' => substr(uniqid(rand(), true), 0, 10),
              'createdOn' => AnDomainAttributeDate::getInstance(),
        )));
    }
743795
protected function _afterEntityInstantiate(AnConfig $config)
    {
        $entity = $config->entity;

        //set the last commentor to the author
        if ($this->getService()->has('com:people.viewer')) {
            $config->append(array(
                'data' => array(
                    'lastCommenter' => $this->getService('com:people.viewer'),
                ),
            ));
        }
    }
610418
public function insert($entity)
    {
        $data     = $this->builder->reduce($entity);
        $entityId = $this->entityRegistry->getEntityId($entity);

        #try
        #{
        $this->connection->insert($this->tableName, $data);

        if (empty($entityId)) {
            $this->entityRegistry->setEntityId($entity, $this->connection->lastInsertId());
        }

        $this->builder->resolve($entity);
        #}
        #catch (\Exception $e)
        #{
        #	throw new OrmException("Entity with id {$entityId} already exists.\n" . $e->getMessage(), 0, $e);
        #}
    }
1287990
public function save(EntityInterface $entity)
    {
        $entity = $this->beforeSave($entity);

        $this->getEntityManager()->persist($entity);
        $this->getEntityManager()->flush($entity);

        $this->afterSave($entity);
    }
1086320
protected function checkIsCorrectEntityType(EntityInterface $entity): void
    {
        $entityFqn = $this->getEntityFqn();

        if (!$entity instanceof $entityFqn) {
            $class = \get_class($entity);
            $msg   = "[ $class ] is not an instance of [ $entityFqn ]";
            throw new DoctrineStaticMetaException($msg);
        }
    }
289710
protected function setDefaultValues($entity)
    {
        $entityClass = ClassUtils::getClass($entity);

        $meta = $this->extendedMetadataFactory->getExtendedMetadata($entityClass);

        if (!isset($meta['defaultValues']) || empty($meta['defaultValues'])) {
            return;
        }

        $defaultValuesMap = $meta['defaultValues'];
        $this->filterDefaultValuesMap($defaultValuesMap, $entity, $entityClass);

        if (empty($defaultValuesMap)) {
            return;
        }

        $sourcePropertyValues = $this->getSourcePropertyValues(
            array_unique(array_values($defaultValuesMap)),
            $entity,
            $entityClass
        );

        $recomputeChangeSet = false;

        foreach ($defaultValuesMap as $targetProperty => $sourcePropertyPath) {
            if (null === $sourcePropertyValues[$sourcePropertyPath]) {
                continue;
            }
            if (!$this->propertyAccessor->isWritable($entity, $targetProperty)) {
                throw new DefaultValueException(sprintf('Property "%s::$%s" is not writable.', $entityClass, $targetProperty));
            }

            $this->propertyAccessor->setValue($entity, $targetProperty, $sourcePropertyValues[$sourcePropertyPath]);

            $recomputeChangeSet = true;
        }
        if ($recomputeChangeSet) {
            $this->recomputeChangeSet($entity);
        }
    }
1370553
protected function _injectEntity(EntityInterface $entity, ArrayObject $options, array $fields)
    {
        $new = $entity->isNew() !== false;

        foreach ($fields as $field => $when) {
            if (!in_array($when, ['always', 'new', 'existing'])) {
                throw new UnexpectedValueException(sprintf(
                    'When should be one of "always", "new" or "existing". The passed value "%s" is invalid',
                    $when
                ));
            }

            if ($entity->isDirty($field)) {
                continue;
            }

            if ($when === 'always' ||
                ($when === 'new' && $new) ||
                ($when === 'existing' && !$new)
            ) {
                $entity->set(
                    $field,
                    Hash::get(
                        $options,
                        $this->getConfig('propertiesMap.' . $field)
                    )
                );
            }
        }
    }
687673
public function generateProxyClass($entity, $config)
    {
        if (!is_array($config) && !$config instanceof \ArrayAccess) {
            throw new Exception\InvalidArgumentException(
                'Invalid proxy class configuration; array or instance of ArrayAccess expected');
        }
        
        if (!is_object($entity)) {
            if ((is_string($entity) && (!class_exists($entity))) // non-existent class
                    || (!is_string($entity)) // not an object or string
            ) {
                throw new Exception\InvalidArgumentException(sprintf(
                        '%s expects an object or valid class name; received "%s"',
                        __METHOD__,
                        var_export($entity, 1)
                ));
            }
        }
        
        $this->serviceConfig = $config;
        
        $reflection  = new ReflectionClass($entity);
        $className = $reflection->getName();
        
        $class = ClassGenerator::fromArray([
            'name' => $this->getProxyClassName($className),
            'namespace_name' => $this->getProxyNamespace($className),
            'extended_class' => '\\' . $className,
            'implemented_interfaces' => array('\Zend\EventManager\EventManagerAwareInterface'),
            'methods' => $this->generateMethods($reflection),
            'properties' => [
                new PropertyGenerator('__wrappedObject', null, PropertyGenerator::FLAG_PUBLIC),
                new PropertyGenerator('__eventManager', null, PropertyGenerator::FLAG_PRIVATE),
                new PropertyGenerator('__commandStack', null, PropertyGenerator::FLAG_PRIVATE)
            ]
        ]);
        
        $source = "<?php\n" . $class->generate();
        
        $fileName        = $this->getProxyFileName($className);
        $parentDirectory = $this->proxyDirectory;
        
        if ( ! is_dir($parentDirectory) && (false === @mkdir($parentDirectory, 0775, true))) {
            throw new Exception\RuntimeException('Proxy directory '.$parentDirectory.' not found');
        }
        
        if ( ! is_writable($parentDirectory)) {
            throw new Exception\RuntimeException('Proxy directory '.$parentDirectory.' is not writable');
        }
        
        $tmpFileName = $fileName . '.' . uniqid('', true);
        file_put_contents($tmpFileName, $source);
        rename($tmpFileName, $fileName);
    }
1142485
public function setConfig(array $config)
    {
        if (!isset($config['thumbnailer'])) {
            $this->_thumbnailer = new Thumbnailer();
        } elseif (class_exists($config['thumbnailer'])) {
            $this->_thumbnailer = new $config['thumbnailer'];
        } else {
            throw new ConfigurationException('Class ' . $config['thumbnailer'] . ' does not exist.');
        }

        if (!($this->_thumbnailer instanceof ThumbnailerInterface)) {
            throw new ConfigurationException('Class ' . get_class($this->_thumbnailer) . ' must implement the interface \ysaroka\autothumb\ThumbnailerInterface.');
        }

        if (!isset($config['document_root'])) {
            throw new ConfigurationException('"document_root" key is required.');
        }

        if (!is_dir(realpath($config['document_root']))) {
            throw new ConfigurationException('"document_root": directory "' . $config['document_root'] . '" does not exist.');
        }

        if (!isset($config['types']) || count($config['types']) == 0) {
            throw new ConfigurationException('"types" key is required and should not be empty.');
        }

        foreach ($config['types'] as $type => $params) {
            if (!preg_match('#^[\w\d]+$#', $type)) {
                throw new ConfigurationException('"type": type name "' . $type . '" must contain only words and numbers.');
            }

            if (!isset($params['width'])) {
                $config['types'][$type]['width'] = 100;
            }

            if (!isset($params['height'])) {
                $config['types'][$type]['height'] = 100;
            }

            if (!isset($params['crop'])) {
                $config['types'][$type]['crop'] = true;
            }

            if (!isset($params['stretch'])) {
                $config['types'][$type]['stretch'] = false;
            }

            if (!isset($params['watermark'])) {
                $config['types'][$type]['watermark'] = false;
            } elseif (file_exists($params['watermark']) && !is_dir($params['watermark'])) {
                $config['types'][$type]['watermark'] = realpath($params['watermark']);
                if (isset($params['watermark_pos']) && defined('\ysaroka\autothumb\ThumbnailerInterface::POS_' . strtoupper($params['watermark_pos']))) {
                    $config['types'][$type]['watermark_pos'] = constant('\ysaroka\autothumb\ThumbnailerInterface::POS_' . strtoupper($params['watermark_pos']));
                } else {
                    $config['types'][$type]['watermark_pos'] = ThumbnailerInterface::POS_BOTTOM_RIGHT;
                }
            } else {
                throw new ConfigurationException('Image file "watermark": "' . $params['watermark'] . '" for type "' . $type . '" does not exist.');
            }
        }

        if (isset($config['allowed_extensions']) && is_array($config['allowed_extensions']) && count($config['allowed_extensions']) > 0) {
            $this->_allowedExtensions = $config['allowed_extensions'];
        }

        $this->_documentRoot = realpath($config['document_root']);
        $this->_types = $config['types'];

        return $this;
    }
457852
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) {
		if ($this->_config['on'] !== 'afterSave') {
			return;
		}

		if (!$entity->isDirty($this->getConfig('field'))) {
			return;
		}

		$value = $entity->get($this->getConfig('field'));
		if (!$value && !$this->getCurrent($entity)) {
			// This should be caught with a validation rule as this is not normal behavior
			throw new LogicException();
		}

		$this->removeFromOthers($entity);
	}
218310
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof EmailConfiguration) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', EmailConfiguration::class)
            );
        }

        $this->validateEmailSender($entity->getEmailSender());
        $this->validateEmailSenderName($entity->getEmailSenderName());
        $this->validateEmailSubjectPrefix($entity->getEmailSubjectPrefix());
        $this->validateEmailBodySignature($entity->getEmailBodySignature());

        $errors = $this->getErrors();

        return empty($errors);
    }
960300
protected function ormLoad(array $config, ContainerBuilder $container)
    {
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('orm.xml');

        $entityManagers = [];
        foreach (array_keys($config['entity_managers']) as $name) {
            $entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name);
        }
        $container->setParameter('doctrine.entity_managers', $entityManagers);

        if (empty($config['default_entity_manager'])) {
            $tmp                              = array_keys($entityManagers);
            $config['default_entity_manager'] = reset($tmp);
        }
        $container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']);

        $options = ['auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace'];
        foreach ($options as $key) {
            $container->setParameter('doctrine.orm.' . $key, $config[$key]);
        }

        $container->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager']));
        $container->getAlias('doctrine.orm.entity_manager')->setPublic(true);

        $config['entity_managers'] = $this->fixManagersAutoMappings($config['entity_managers'], $container->getParameter('kernel.bundles'));

        $loadPropertyInfoExtractor = interface_exists(PropertyInfoExtractorInterface::class)
            && class_exists(DoctrineExtractor::class);

        foreach ($config['entity_managers'] as $name => $entityManager) {
            $entityManager['name'] = $name;
            $this->loadOrmEntityManager($entityManager, $container);

            if ($loadPropertyInfoExtractor) {
                $this->loadPropertyInfoExtractor($name, $container);
            }

            $this->loadValidatorLoader($name, $container);
        }

        if ($config['resolve_target_entities']) {
            $def = $container->findDefinition('doctrine.orm.listeners.resolve_target_entity');
            foreach ($config['resolve_target_entities'] as $name => $implementation) {
                $def->addMethodCall('addResolveTargetEntity', [
                    $name,
                    $implementation,
                    [],
                ]);
            }

            $def->addTag('doctrine.event_subscriber');
        }

        $container->registerForAutoconfiguration(ServiceEntityRepositoryInterface::class)
            ->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG);

        $this->loadMessengerServices($container);
    }
1192985
public function update($entity)
    {
        if ($this->idProperty === null) {
            throw new ConfigurationException('No idProperty set');
        }

        $id = $this->idProperty->getValue($entity);

        if ($id === null) {
            throw new ConfigurationException('Value of ' . $this->idProperty->getName() . ' is null');
        }

        $values = $this->getInsertValues($entity, $this->namingContention);
        $keyString = implode(array_keys($values), ' = ?,') . ' = ?';
        $idColumn = $this->namingContention->propertyToColumnName($this->idProperty);
        $onlyValues = array_values($values);
        $onlyValues[] = $id;

        $sql = "UPDATE $this->tableName SET $keyString WHERE $idColumn = ?";
        $sth = $this->pdo->prepare($sql);
        $sth->execute($onlyValues);
        return $id;
    }
1031210
public function setConfig( array $config )
	{
		if ( $config == $this->getConfig() ) { return; }

		$this->_values['config'] = $config;
		$this->setModified();
	}