Sets the Entity Factory which will create the Entities from Responses
@param EntityFactory $factory
@return $this
973378
public function setEntityFactory(EntityFactory $factory = null)
    {
        if ($factory === null) {
            $factory = new Entity();
        }
        $this->factory = $factory;
        return $this;
    }
123340
public function itemWith($entity, $transformer, $key = null): TransformationFactory
	{
		$this->entity      = $entity;
		$this->transformer = $transformer;
		$this->resource    = new Item($entity, $transformer, $key);

		return $this;
	}
1224067
public function setDatasources(DatasourceFactory $factory, array $datasources) {
        $this->datasourceFactory = $factory;
        $this->datasources = $datasources;
    }
1059606
protected function createFactory()
    {
        if (!class_exists($this->factoryClass)) {
            throw new RuntimeException(sprintf(
                'Failed to create an instance of non-existing factory class "%s".',
                $this->factoryClass
            ));
        }

        $class = $this->factoryClass;

        switch (count($this->args)) {
            case 0:
                $factory = new $class();
                break;

            case 1:
                $factory = new $class($this->args[0]);
                break;

            case 2:
                $factory = new $class($this->args[0], $this->args[1]);
                break;

            case 3:
                $factory = new $class($this->args[0], $this->args[1], $this->args[2]);
                break;

            case 4:
                $factory = new $class($this->args[0], $this->args[1], $this->args[2], $this->args[3]);
                break;

            default:
                $reflection = new ClassReflection($class);
                $factory = $reflection->newInstanceArgs($this->args);
                break;
        }

        if (!$factory instanceof FactoryInterface) {
            throw new LogicException(sprintf(
                'Invalid service factory. Factory is expected to be an instance of %s, %s given.',
                'Zend\ServiceManager\FactoryInterface',
                get_class($factory)
            ));
        }

        return $factory;
    }
248453
public function setEntity(Entity $entity)
    {
        $this->each(
            function(Record $record) use ($entity) {
                $record->setEntity($entity);
                $record->setEntityClass(get_class($entity));
            }
        );

        return $this;
    }
674451
public function setEntityLoaderRepository($entityLoaderRepository)
    {
        // force mode
        $this->setEntityLoaderMode(self::ENTITY_LOADER_REPOSITORY);

        $this->entityLoaderRepository = $entityLoaderRepository;

        return $this;
    }
251829
public function addClassMatcherFactory(ClassMatcherFactoryInterface $factory)
    {
        $this->classMatcherFactories[$factory->getType()] = $factory;

        if ($factory instanceof AbstractLogicalFactory) {
            $factory->setNamingStrategy($this);
        }

        return $this;
    }
810649
public function setEntity($entity_name, $entity_alias)
    {
        $this->entityName = $entity_name;
        $this->entityAlias = $entity_alias;
        $this->queryBuilder->from($entity_name, $entity_alias);

        return $this;
    }
341254
final public function factory($factory)
    {
        if (\is_string($factory) && 1 === substr_count($factory, ':')) {
            $factoryParts = explode(':', $factory);

            throw new InvalidArgumentException(sprintf('Invalid factory "%s": the "service:method" notation is not available when using PHP-based DI configuration. Use "[ref(\'%s\'), \'%s\']" instead.', $factory, $factoryParts[0], $factoryParts[1]));
        }

        $this->definition->setFactory(static::processValue($factory, true));

        return $this;
    }
163002
public static function AddFactory( &$factories)
	{
		foreach ( $factories as /** @var ValueProxyFactory $curr */ $curr )
		{
			if ( count( ValueProxy::$valueFactory ) == ValueProxy::TYPES_MAX )
				throw new InvalidOperationException();

			ValueProxy::$valueFactory[ $curr->GetValueType()->getTypeName() ] = $curr;
		}
		ValueProxy::Bind();
	}
1209864
public function setEntityType(string $entityType): void {
		if (!class_exists($entityType)) {
			throw new EntityFactoryException("Unknown entity: $entityType.", EntityFactoryException::UNKNOWN_ENTITY);
		}
		
		// now that we know a class with the name of entityType exists, we need
		// to see if it is an implementation of our EntityInterface object.  the
		// use of the Aura DI container to inject dependencies seems to prevent
		// the use of the PHP is_a() and is_subclass_of() functions.  instead,
		// we'll try to instantiate it like it's an EntityInterface and then we
		// can use the instanceof operator to be sure.
		
		$this->entityType = $entityType;
		$temp = $this->newEntity([]);
		
		if (!($temp instanceof EntityInterface)) {
			
			// if that didn't work, then not only do we want to throw an
			// exception, but we also want to be sure that we set the
			// entityType property back to null so that it doesn't accidentally
			// get used elsewhere after the exception is caught.
			
			$this->entityType = null;
			throw new EntityFactoryException("Not an entity: $entityType.", EntityFactoryException::NOT_AN_ENTITY);
		}
	}
1340359
public function setMigrationFactory(FactoryInterface $factory)
    {
        foreach ($this->getRepositories() as $repo) {
            $repo->setMigrationFactory($factory);
        }
    }
199825
public function setFactory($factory)
    {
        $this->changes['factory'] = true;

        if (\is_string($factory) && false !== strpos($factory, '::')) {
            $factory = explode('::', $factory, 2);
        } elseif ($factory instanceof Reference) {
            $factory = [$factory, '__invoke'];
        }

        $this->factory = $factory;

        return $this;
    }
542641
public function setFactoryMode($factory = true) {
		$this->factoryMode = (bool) $factory;
		
		if ($this->factoryMode) {
			$this->reset();
		}
		
		return $this;
	}
47455
public function register(callable $factory): self
    {
        $this->data->register($factory, $this->crtPriority);
        return $this;
    }
511878
public function create(
        EntityFactoryConfig $config,
        ServerRequestInterface $request,
        ResponseInterface $response,
        callable $next
    ): ResponseInterface {
        $entityRequest = $config->createEntityRequest($request, $this->container);

        # make a new empty record
        $obj = $entityRequest->instantiateActiveRecord();

        # Execute beforeCreate hook, which can alter record
        $entityRequest->beforeCreate($obj, $request);

        # Then, alter object with allowed properties
        if ($config->isHydrateEntityFromRequest()) {
            $requestParams = $request->getQueryParams();
            $postParams    = $request->getParsedBody();
            if ($postParams) {
                $requestParams = array_merge($requestParams, (array)$postParams);
            }

            /** @noinspection PhpUndefinedMethodInspection */
            $obj->fromArray($entityRequest->getAllowedDataFromRequest($requestParams, $request->getMethod()));
        }

        # Execute afterCreate hook, which can alter record
        $entityRequest->afterCreate($obj, $request);

        $request = $request->withAttribute($config->getParameterToInjectInto(), $obj);
        /** @var Response $response */
        return $next($request, $response);
    }
1340915
public static function toObservable(callable $factory)
    {
        $observableFactory = function () use ($factory) {
            return Promise::toObservable($factory());
        };

        return Observable::defer($observableFactory);
    }