public function createResource($newResource, $baseResource)
    {
        $em = $this->getEntityManager();
        // Check if the base resource exists, otherwise create it.
        if (!$baseResource instanceof ResourceEntity &&
            !is_string($baseResource)) {
            throw new \Exception('Base resource is not a valid ACL resource, ' . get_class($baseResource) . ' given.');
        } elseif (!$baseResource instanceof \ResourceEntity) {
            $baseName     = $baseResource;
            $baseResource = $em->getRepository('JaztecAcl\Entity\Acl\Resource')->findOneBy(['name' => $baseName]);
            if (!$baseResource instanceof ResourceEntity) {
                $baseResource = new \JaztecAcl\Entity\Acl\Resource($baseName);
                $baseResource->setSort(0);
                $em->persist($baseResource);
                $this->addResource($baseResource->getResourceId());
            }
        }
        // Checking the new resource on validity
        if (!is_string($newResource)) {
            throw new \Exception('The new resource is not a valid string');
        }

        // Create the new (unknown) resource and add it to the ACL.
        $resource = new \JaztecAcl\Entity\Acl\Resource($newResource, $baseResource, $baseResource->getSort() + 1);
        $em->persist($resource);

        $em->flush();

        $this->addResource($resource, $resource->getParent());

        return $resource;
    }