@param ResourceInterface $resource

@return Definition
15459
private function createRepositoryDefinition(ResourceInterface $resource)
    {
        $definition = new Definition($resource->getRepository(), [$resource->getModel()]);
        $definition->setFactory([new Reference('lug.manager.'.$resource->getName()), 'getRepository']);
        $definition->addTag('lug.repository', ['resource' => $resource->getName()]);

        return $definition;
    }
812409
public function includedData(ResourceInterface $resource, array $data)
    {
        list($serializedData, $linkedIds) = $this->pullOutNestedIncludedData($data);

        foreach ($data as $value) {
            foreach ($value as $includeObject) {
                if ($this->isNull($includeObject) || $this->isEmpty($includeObject)) {
                    continue;
                }

                $includeObjects = $this->createIncludeObjects($includeObject);
                list($serializedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey($includeObjects, $linkedIds, $serializedData);
            }
        }

        return empty($serializedData) ? [] : ['included' => $serializedData];
    }
1113455
private function parseResource(ResourceInterface $resource): iterable
    {
        $seenBefore = isset($this->resourcesTracker[$resource->getId()][$resource->getType()]);

        // top level resources should be yielded in any case as it could be an array of the resources
        // for deeper levels it's not needed as they go to `included` section and it must have no more
        // than one instance of the same resource.

        if ($seenBefore === false || $resource->getPosition()->getLevel() <= ParserInterface::ROOT_LEVEL) {
            yield $resource;
        }

        // parse relationships only for resources not seen before (prevents infinite loop for circular references)
        if ($seenBefore === false) {
            // remember by id and type
            $this->resourcesTracker[$resource->getId()][$resource->getType()] = true;

            foreach ($resource->getRelationships() as $name => $relationship) {
                \assert(\is_string($name));
                \assert($relationship instanceof RelationshipInterface);

                $isShouldParse = $this->isPathRequested($relationship->getPosition()->getPath());

                if ($isShouldParse === true && $relationship->hasData() === true) {
                    $relData = $relationship->getData();
                    if ($relData->isResource() === true) {
                        yield from $this->parseResource($relData->getResource());

                        continue;
                    } elseif ($relData->isCollection() === true) {
                        foreach ($relData->getResources() as $relResource) {
                            \assert($relResource instanceof ResourceInterface ||
                                $relResource instanceof IdentifierInterface);
                            if ($relResource instanceof ResourceInterface) {
                                yield from $this->parseResource($relResource);
                            }
                        }

                        continue;
                    }

                    \assert($relData->isNull() || $relData->isIdentifier());
                }
            }
        }
    }
72402
protected function doDeleteResource(ResourceInterface $resource, $soft)
    {
        $skipped = false;
        $object = $resource->getRealData();

        if ($object instanceof SoftDeletableInterface) {
            if ($soft) {
                if ($object->isDeleted()) {
                    $skipped = true;
                } else {
                    $this->doDeleteResourceAction($resource);
                }
            } else {
                if (!$object->isDeleted()) {
                    $object->setDeletedAt(new \DateTime());
                }
                $this->doDeleteResourceAction($resource);
            }
        } else {
            $this->doDeleteResourceAction($resource);
        }

        return $skipped;
    }
377680
public function set(ResourceInterface $resource): ResourceCollectionInterface
    {
        $this->collection[$this->buildArrayKey($resource->type(), $resource->id())] = $resource;

        return $this;
    }
84832
public function setResource($resource)
    {
        $res = $this->driverInstance->setResource($resource);
        if (!$this->isInstanceOf($res, YamlInterface::class)) {
            throw new YamlException('YamlInterface method setSource() must return YamlInterface object.');
        }

        return $this;
    }
259192
public function add(ResourceInterface $resource)
    {
        $this->resources[$resource->getName()] = $resource;
        $this->indexes[] = $resource->getName();

        return $this;
    }
663280
public function getResource($resource)
    {
        if (array_key_exists($resource, $this->cache)) {
            return $this->cache[$resource];
        }

        if (!array_key_exists($resource, $this->resources)) {
            throw new ResourceNotImplemented($resource);
        }

        $params = $this->resources[$resource];
        $instance = $params['instance'];

        if (is_null($instance)) {
            $class = $params['class'];

            $instance = new $class($this);
        }

        return $this->cache[$resource] = $instance;
    }
1279847
protected function findPermission(RequesterInterface $requester, ResourceInterface $resource)
    {
        if (null === $permission = $this->permissionBuffer->get($requester, $resource)) {
            try {
                $mask = $this->databaseProvider->findMask($requester, $resource);
            } catch (MaskNotFoundException $e) {
                throw new PermissionNotFoundException($requester, $resource);
            }

            $permission = $this->initPermission($requester, $resource, $mask);
            $permission->setPersistent(true);

            $this->permissionBuffer->add($permission);
        }

        return $permission;
    }
765911
private function createChoiceFormDefinition(ResourceInterface $resource)
    {
        $definition = new Definition($resource->getChoiceForm(), [
            new Reference('lug.resource.'.$resource->getName()),
        ]);

        $definition->addTag('form.type');

        return $definition;
    }
498487
protected function doDeleteResourceAction(ResourceInterface $resource): void
    {
        try {
            $this->om->remove($resource->getRealData());
        } catch (\Exception $e) {
            DomainUtil::injectErrorMessage($this->translator, $resource, $e, $this->debug);
        }
    }
292423
public function removeElement(ResourceInterface $resource): ResourceCollectionInterface
    {
        $this->remove($resource->type(), $resource->id());

        return $this;
    }
1174132
private function createFormDefinition(ResourceInterface $resource)
    {
        $definition = new Definition($resource->getForm(), [
            new Reference('lug.resource.'.$resource->getName()),
            new Reference('lug.factory.'.$resource->getName()),
        ]);

        $definition->addTag('form.type');

        return $definition;
    }
756753
public static function fromResource(ResourceInterface $resource, $path)
	{
		if ($resource instanceof FileResourceInterface) {
			return $resource;
		}
		file_put_contents($path, $resource->getStream());
		$attr = [
			'mimetype' => $resource->getMimetype(),
			'lastmodified' => $resource->getLastModified(),
			'filename' => $resource->getFilename()
		];
		return new FileResource($path, $attr);
	}
201411
protected function getResourceName($resource)
    {
        if ($resource instanceof ResourceInterface) {
            $resource = $resource->getName();
        }

        if (false === is_string($resource)) {
            throw new InvalidArgumentException(
                'Resource argument must be string or an object implemented "Rad\Authorization\Rbac\ResourceInterface".'
            );
        }

        return $resource;
    }
1111094
private function getClassMetadata(ResourceInterface $resource)
    {
        $entityClass = $resource->getEntityClass();

        return $this
            ->managerRegistry
            ->getManagerForClass($entityClass)
            ->getClassMetadata($entityClass)
        ;
    }
122504
private function generateResourceName($resource)
    {
        if (false === $this->pluralize) {
            return $resource;
        }

        return $this->inflector->pluralize($resource);
    }