@param object       $owner
@param object|array $sample
@param int          $size
@param string       $type

@return static
8644
public function add($owner, $sample, $size = 1, $type = 'default')
    {
        $size = MANAPHP_COROUTINE ? $size : 1;

        $owner_id = spl_object_id($owner);

        if (!isset($this->_pool[$owner_id][$type])) {
            $this->_pool[$owner_id][$type] = $queue = new \SplQueue();
        } else {
            $queue = $this->_pool[$owner_id][$type];
        }

        if (is_array($sample)) {
            $class = $sample['class'];
            unset($sample['class']);
            $sample = $this->_di->getInstance($class, $sample);
        }

        $queue->push(clone $sample);

        for ($i = 1; $i < $size; $i++) {
            $queue->push(clone $sample);
        }

        return $this;
    }
623167
public static function calculate(string $type, string $size, string $payload): string
    {
        $crc = $type ^ $size;

        if (!empty($payload)) {
            foreach (str_split($payload) as $payloadByte) {
                $crc = $crc ^ $payloadByte;
            }
        }

        return $crc;
    }
974100
public static function getInstance($type, $init)
    {

        if (!self::$cachingInstance) {
            self::$cachingInstance = new IDS_Caching_Database($type, $init);
        }
        return self::$cachingInstance;
    }
563969
public void putField(Type owner, String name, Type type) {
    adapter.putField(owner, name, type);
  }
278275
public function saveRecord (MapElement $map, $ownerId, $ownerSiteId, $fieldId, $isNew)
	{
		$record = null;

		if (!$isNew)
		{
			$record = MapRecord::findOne($map->id);

			if (!$record)
				throw new \Exception('Invalid map ID: ' . $map->id);
		}

		if ($record === null)
		{
			$record = new MapRecord();

			$record->id          = $map->id;
			$record->ownerId     = $ownerId;
			$record->ownerSiteId = $ownerSiteId;
			$record->fieldId     = $fieldId;
		}

		$record->lat     = $map->lat;
		$record->lng     = $map->lng;
		$record->zoom    = $map->zoom;
		$record->address = $map->address;
		$record->parts   = $map->parts;

		$this->_populateMissingData($record);

		$record->save(false);
	}
1203876
protected function morphEagerTo($name, $type, $id, $ownerKey)
    {
        return $this->newMorphTo(
            $this->newQuery()->setEagerLoads([]), $this, $id, $ownerKey, $type, $name
        );
    }
328832
protected function createRequest(string $host, int $type): Request
    {
        $request = new Request();
        $request->addQuestion($host, $type);
        $request->setRecursionDesired(true);
        
        return $request;
    }
8383
public function createBlock($owner, $type, $parentId, $placeholder, $sort, $data = null, $draft = true)
    {
        /** @var AbstractBlockService $service */
        $service = $this->getService($type);
        $parent = $parentId ? $this->find($parentId, $draft) : null;

        // This should replaced with a more hardened function
        if (is_null($data)) {
            $data = array();
        }
        $data['owner'] = $owner;

        $block = $service->createBlock($data);

        $block->setPosition($placeholder);
        $block->setSort(0); // < default, gets recalculated later for entire level
        $block->setSortParent(-1); // < need to be calculated when putting in the tree

        // Set owner
        if (is_null($parent) || false === $parent->isShared()) {
            $block->setOwner($owner);
        }

        $block->setParent($parent);

        // Save now, rest will be in changeset. All we do is a create a stub entry anyway.
        $this->save($block, $draft);

        if (count($sort) > 1) {
            // Replace the zero value in the posted sort array
            // with the newly created id to perform sorting
            $id = $block->getId();
            $sort = array_map(
                function ($v) use ($id) {
                    return $v == "" || $v == "0" ? $id : $v;
                },
                $sort
            );

            array_walk($sort, function (&$id) { $id = (int) $id; });
            $contained = $this->findById($sort, $draft);

            if ($contained) {
                $contained = $this->setSortsByDirective($contained, $sort);

                foreach ($contained as $node) {
                    // If nodes are in the same parent and if their owners match we
                    // save the changes. We don't want to save sort changes made to
                    // nodes belonging to inherited trees.
                    if ($node->getParent() === $block->getParent() &&
                        (($node->getOwner() === null && $block->getOwner() === null) ||
                        ($node->getOwner()->getId() == $block->getOwner()->getId()))) {
                        $this->save($node, $draft);
                    }
                }
            }
        }

        return $block;
    }
77047
public static function create(
        $body,
        TypeResolver $typeResolver = null,
        DescriptionFactory $descriptionFactory = null,
        TypeContext $context = null
    )
    {
        Assert::stringNotEmpty($body);
        Assert::allNotNull([$typeResolver, $descriptionFactory]);

        preg_match(self::REGEXP, $body, $parts);

        $description = null;

        if (null !== $descriptionFactory) {
            $descriptionStr = isset($parts['description']) ? trim($parts['description']) : '';
            $description = $descriptionFactory->create($descriptionStr, $context);
        }

        $typeStr = isset($parts['type']) ? trim($parts['type']) : 'mixed';
        $typeExtended = $parts['typeFormat'] ?? null;
        $variableName = $parts['variableName'] ?? 'variable';

        $type = CustomTypeResolver::resolve($typeStr, $typeExtended);

        /** @var static $param */
        $param = new static($variableName, $type, $description);

        $param->setOptional(empty($parts['require']));

        if (!empty($parts['defaultValue'])) {
            $param->setDefault(self::getRealValue($parts['defaultValue']));
        }
        if (!empty($parts['exampleValue'])) {
            $param->setExample(self::getRealValue($parts['exampleValue']));
        }

        return $param;
    }
37079
public function getImageWidth($type, $size)
	{
		if (empty($this->$type))
		{
			return null;
		}
		$method = $this->getImageConfig($type, $size, 'method');

		// Width varies for images that are 'portrait', 'auto', 'fit', 'crop'
		if (in_array($method, array('portrait', 'auto', 'fit', 'crop')))
		{
			list($width) = $this->getImageDimensions($type, $size);
			return $width;
		}
		return $this->getImageConfig($type, $size, 'width');
	}
799311
private function executePrivilege($type, $privilege, $username, $database = null)
    {

        if (!in_array($privilege, [self::PRIVILEGE_READ, self::PRIVILEGE_WRITE, self::PRIVILEGE_ALL], true)) {
            throw new Exception($privilege . ' is not a valid privileges, allowed privileges: READ, WRITE, ALL');
        }

        if ($privilege !== self::PRIVILEGE_ALL && !$database) {
            throw new Exception('Only grant ALL cluster-wide privileges are allowed');
        }

        $database = ($database instanceof Database ? $database->getName() : (string) $database);

        $query = "$type $privilege";

        if ($database) {
            $query .= sprintf(' ON %s ', $database);
        } else {
            $query .= ' PRIVILEGES ';
        }

        if ($username && $type === 'GRANT') {
            $query .= "TO $username";
        } elseif ($username && $type === 'REVOKE') {
            $query .= "FROM $username";
        }

        return $this->client->query(null, $query);
    }
1209525
public static function getInstance($type, $authenticator, $domain)
	{
		$query = self::all()
			->whereEquals('type', $type)
			->whereEquals('authenticator', $authenticator);
		if ($domain)
		{
			$query->whereEquals('domain', $domain);
		}
		$row = $query->row();

		if (!$row || !$row->get('id'))
		{
			return false;
		}

		return $row;
	}
1033314
public function initUpload(string $hash, int $size, string $name, string $type, ?string $context = null): bool
    {

        if (!$context || $this->contextSupport) {
            $entity = $this->repository->findByHash($hash, $context, false);
            if (!$entity) {
                $entity = $this->createEntity($hash, $context);
            }

            $entity->setSize(0);
            $entity->setContents('');
            $entity->setLastUpdateDate(time());
            $entity->setConfirmed(false);

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

            return true;
        }
        return false;
    }
168339
private function makeSomeProxies(int $amount, ?object $owner): array
    {
        $proxies = [];
        for ($i = 0; $i < $amount; ++$i) {
            $proxies[] = $this->proxyBuilder->createFor($owner, $this->name(), $i);
        }
        return $proxies;
    }
5316
public static function instance($size = null, $order = 'id', $dir = 'desc'): Page
    {
        static $handle;
        if (!$handle) {
            $handle = new self ($size, $order, $dir);
        }
        return $handle;
    }
1181001
public function createAskResourceOwnerForApprovalResponse(
        string $type,
        ClientInterface $client,
        string $redirectUri = null,
        bool $isScopeModified = false,
        array $scopeList = null,
        string $state = null,
        array $extraParameters = []
    ): ResponseInterface {
        /** @var Client $client */
        assert($client instanceof Client);

        // TODO think if we can receive objects instead of individual properties
        $scopeList = empty($scopeList) === true ? null : implode(' ', $scopeList);
        $filtered  = array_filter([
            self::SCOPE_APPROVAL_TYPE              => $type,
            self::SCOPE_APPROVAL_CLIENT_ID         => $client->getIdentifier(),
            self::SCOPE_APPROVAL_CLIENT_NAME       => $client->getName(),
            self::SCOPE_APPROVAL_REDIRECT_URI      => $redirectUri,
            self::SCOPE_APPROVAL_IS_SCOPE_MODIFIED => $isScopeModified,
            self::SCOPE_APPROVAL_SCOPE             => $scopeList,
            self::SCOPE_APPROVAL_STATE             => $state,
        ], function ($value) {
            return $value !== null;
        });

        return new RedirectResponse($this->createRedirectUri($this->getApprovalUriString(), $filtered));
    }
881926
public function setCreatorOwner(string $creator_owner = "T") : CNabuDataObject
    {
        if ($creator_owner === null) {
            throw new ENabuCoreException(
                    ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
                    array("\$creator_owner")
            );
        }
        $this->setValue('nb_user_group_type_creator_owner', $creator_owner);
        
        return $this;
    }