Create a new EntityInstance

@param string $identity Unique identity of the Entity
@return EntityInstance Newly created EntityInstance
@throws TwilioException When an HTTP error occurs.
180876
public function create($identity) {
        $data = Values::of(array('Identity' => $identity, ));

        $payload = $this->version->create(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new EntityInstance($this->version, $payload, $this->solution['serviceSid']);
    }
617447
private function createInstance($id)
    {
        $schema = $this->getAndValidateServiceSchema($id);

        $reflection = new ReflectionClass($schema['class']);
        $arguments = $schema['arguments'];

        if ($factoryMethod = $this->getAndValidateFactoryMethod($reflection, $schema)) {
            return $factoryMethod->invokeArgs(null, $arguments);
        }

        return $reflection->newInstanceArgs($arguments);
    }
325931
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var PluginWrapper $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        // if no id, then it has not been save and can be returned
        if (empty($new->pluginWrapperId)) {
            return $new;
        }

        $new->pluginWrapperId = null;

        // @deprecated <deprecated-site-wide-plugin>
        //if (!$new->instance->isSiteWide()) {
            $pluginInstance = $new->instance->newInstance(
                $createdByUserId,
                $createdReason
            );
            $new->instance = $pluginInstance;
        //}

        return $new;
    }
1148717
public function withSubjectUniqueID(UniqueIdentifier $id): self
    {
        $obj = clone $this;
        $obj->_subjectUniqueID = $id;
        return $obj;
    }
463197
public function createIdentifier($data)
	{
		// Get the data ready for creation.
		switch(gettype($data))
		{
			// Use an Object to update.
			case 'object':
				// Add entity type and key to creation data.
				$createData = ['entity_type' => $data->getType(), 'entity_id' => $data->getKey()];
			break;

			default:
				$createData = $data;
			break;
		}

		// Create the newly created entity's EntityIdentifier.
		return $this->aggregate[IdentifierServiceProvider::getProviderKey()]->create($createData);
	}
695792
public function getUserEntityByIdentifier(string $userIdentifier): UserEntity
    {
        return new UserEntity(Member::get()->filter(['Email' => $userIdentifier])->first());
    }
1137473
protected function validateIdentity($identity)
    {
        $options = $this->options;
        $credential = $options
            ->getCredentialRepository()
            ->findOneBy([
                $options->getCredentialIdentityProperty() => $identity,
                $options->getCredentialTypeProperty() => $options->getCredentialType()
            ]);

        if (!$credential) {
            $this->authenticationResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND;
            $this->authenticationResultInfo['messages'][] = 'A record with the supplied credential could not be found.';

            return $this->createAuthenticationResult();
        }

        $credentialIdentityProperty = $this->options->getCredentialIdentityProperty();
        $getter = 'get' . ucfirst($credentialIdentityProperty);
        $credentialIdentity = null;

        if (method_exists($credential, $getter)) {
            $credentialIdentity = $credential->$getter();
        } elseif (property_exists($credential, $credentialIdentityProperty)) {
            $credentialIdentity = $credential->{$credentialIdentityProperty};
        } else {
            throw new Exception\UnexpectedValueException(
                sprintf(
                    'Property (%s) in (%s) is not accessible. You should implement %s::%s()',
                    $credentialIdentityProperty,
                    get_class($credential),
                    get_class($credential),
                    $getter
                )
            );
        }

        $callable = $this->options->getCredentialCallable();
        if ($callable) {
            $credentialValid = call_user_func($callable, $identity, $credential, $this->credential);
        } else {
            $credentialProperty = $options->getCredentialProperty();
            $getter = 'get' . ucfirst($credentialProperty);
            $credentialValue = null;

            if (method_exists($credential, $getter)) {
                $credentialValue = $credential->$getter();
            } elseif (property_exists($credential, $credentialProperty)) {
                $credentialValue = $credential->{$credentialProperty};
            } else {
                throw new Exception\UnexpectedValueException(
                    sprintf(
                        'Property (%s) in (%s) is not accessible. You should implement %s::%s()',
                        $credentialProperty,
                        get_class($credential),
                        get_class($credential),
                        $getter
                    )
                );
            }

            $credentialValid = $identity === $credentialIdentity && $this->credential === $credentialValue;
        }

        if ($credentialValid !== true) {
            $this->authenticationResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID;
            $this->authenticationResultInfo['messages'][] = 'Supplied credential is invalid.';

            return $this->createAuthenticationResult();
        }

        $this->authenticationResultInfo['code'] = AuthenticationResult::SUCCESS;
        $this->authenticationResultInfo['identity'] = $identity;
        $this->authenticationResultInfo['messages'][] = 'Authentication successful.';

        return $this->createAuthenticationResult();
    }
497916
public static function newInstance(EntityInterface $entity, string $path, string $name = null): self
    {
        if (null === $name) {
            $name = $entity->basename();
        }
        $instance = new static($name, $path);
        $instance->realEntity = $entity;

        return $instance;
    }
381456
protected function _createPlainToken($identity)
    {
        $usernameField = $this->getConfig('fields.username');
        $passwordField = $this->getConfig('fields.password');

        return $identity[$usernameField] . $identity[$passwordField];
    }
172660
public function newAction($id)
    {
        //get the business entity
        $businessEntity = $this->getBusinessEntity($id);

        /** @var BusinessTemplate $view */
        $view = $this->get('victoire_business_page.BusinessTemplate_chain')->getBusinessTemplate($id);
        $view->setBusinessEntityId($businessEntity->getId());

        $form = $this->createCreateForm($view);

        $parameters = [
            'entity' => $view,
            'form'   => $form->createView(),
        ];

        return new JsonResponse([
            'html' => $this->container->get('templating')->render(
                'VictoireBusinessPageBundle:BusinessTemplate:new.html.twig',
                $parameters
            ),
            'success' => true,
        ]);
    }
344910
public function setDatatableId($id)
    {
        if (!array_key_exists($id, self::$_instances))
        {
            self::$_instances[$id] = $this;
        }
        else
        {
            throw new \Exception('Identifer already exists');
        }
        return $this;
    }
547845
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var static $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        // if no id, then it has not been save and can be returned
        if (empty($new->pageId)) {
            return $new;
        }

        $new->pageId = null;
        $new->name = null;
        $new->parent = null;

        return $new;
    }
5411
private function createAggregate(
        Identity $identity,
        object $entity,
        Query $query
    ): Query {
        $meta = ($this->metadata)(\get_class($entity));
        $data = ($this->extract)($entity);
        $varName = $this->name->sprintf(\md5($identity->value()));

        $query = $query->create(
            (string) $varName,
            $meta->labels()->toPrimitive()
        );
        $paramKey = $varName->append('_props');
        $properties = $this->buildProperties(
            $meta->properties(),
            $paramKey
        );
        $keysToKeep = $data->keys()->intersect($properties->keys());

        $query = $query
            ->withProperty(
                $meta->identity()->property(),
                (string) $paramKey
                    ->prepend('{')
                    ->append('}.')
                    ->append($meta->identity()->property())
            )
            ->withProperties($properties->reduce(
                [],
                static function(array $carry, string $property, string $cypher): array {
                    $carry[$property] = $cypher;

                    return $carry;
                }
            ))
            ->withParameter(
                (string) $paramKey,
                $data
                    ->filter(static function(string $key) use ($keysToKeep): bool {
                        return $keysToKeep->contains($key);
                    })
                    ->put(
                        $meta->identity()->property(),
                        $identity->value()
                    )
                    ->reduce(
                        [],
                        static function(array $carry, string $key, $value): array {
                            $carry[$key] = $value;

                            return $carry;
                        }
                    )
            );

        $query = $meta
            ->children()
            ->reduce(
                $query,
                function(Query $carry, string $property, Child $child) use ($varName, $data): Query {
                    return $this->createAggregateChild(
                        $child,
                        $varName,
                        $data->get($property),
                        $carry
                    );
                }
            );
        $this->variables = $this->variables->add((string) $varName);

        return $query;
    }
1023649
public function Create($user, $idempotencyKey = null)
    {
        $className = get_class($user);
        if ($className == 'MangoPay\UserNatural') {
            $methodKey = 'users_createnaturals';
        } elseif ($className == 'MangoPay\UserLegal') {
            $methodKey = 'users_createlegals';
        } else {
            throw new Libraries\Exception('Wrong entity class for user');
        }

        $response = $this->CreateObject($methodKey, $user, null, null, null, $idempotencyKey);
        return $this->GetUserResponse($response);
    }
1003075
public function clone(Context $context, string $entity, string $id): JsonResponse
    {
        $entity = $this->urlToSnakeCase($entity);

        $definition = $this->definitionRegistry->getByEntityName($entity);

        $eventContainer = $this->definitionRegistry->getRepository($definition->getEntityName())->clone($id, $context);
        $event = $eventContainer->getEventByDefinition($definition->getClass());
        if (!$event) {
            throw new NoEntityClonedException($entity, $id);
        }

        $ids = $event->getIds();
        $newId = array_shift($ids);

        return new JsonResponse(['id' => $newId]);
    }
385415
public function createVersion(Request $request, Context $context, string $entity, string $id): Response
    {
        $versionId = $request->query->get('versionId');
        $versionName = $request->query->get('versionName');

        if ($versionId !== null && !Uuid::isValid($versionId)) {
            throw new InvalidUuidException($versionId);
        }

        if ($versionName !== null && !ctype_alnum($versionName)) {
            throw new InvalidVersionNameException();
        }

        try {
            $entityDefinition = $this->definitionRegistry->getByEntityName($entity);
        } catch (DefinitionNotFoundException $e) {
            throw new NotFoundHttpException($e->getMessage(), $e);
        }

        $versionId = $this->definitionRegistry->getRepository($entityDefinition->getEntityName())->createVersion($id, $context, $versionName, $versionId);

        return new JsonResponse([
            'versionId' => $versionId,
            'versionName' => $versionName,
            'id' => $id,
            'entity' => $entity,
        ]);
    }
1034907
private function getEntity($id, $entityClass = null)
    {
        if (empty($entityClass)) {
            $entityClass = $this->entityClass;
        }

        $entity = $this->getEntityManager()->find($entityClass, $id);

        if (empty($entity)) {
            throw $this->createNotFoundException(
                sprintf('Unable to find entity "%s" by ID "%d".', $entityClass, $id)
            );
        }

        return $entity;
    }