Neos\ContentRepository\Domain\Service\Context::getWorkspace PHP Method

getWorkspace() public method

Returns the current workspace.
public getWorkspace ( boolean $createWorkspaceIfNecessary = true ) : Workspace
$createWorkspaceIfNecessary boolean DEPRECATED: If enabled, creates a workspace with the configured name if it doesn't exist already. This option is DEPRECATED, create workspace explicitly instead.
return Neos\ContentRepository\Domain\Model\Workspace The workspace or NULL
    public function getWorkspace($createWorkspaceIfNecessary = true)
    {
        if ($this->workspace !== null) {
            return $this->workspace;
        }
        $this->workspace = $this->workspaceRepository->findByIdentifier($this->workspaceName);
        if ($this->workspace === null && $createWorkspaceIfNecessary) {
            $liveWorkspace = $this->workspaceRepository->findByIdentifier('live');
            $this->workspace = new Workspace($this->workspaceName, $liveWorkspace);
            $this->workspaceRepository->add($this->workspace);
            $this->systemLogger->log(sprintf('Notice: %s::getWorkspace() implicitly created the new workspace "%s". This behaviour is discouraged and will be removed in future versions. Make sure to create workspaces explicitly by adding a new workspace to the Workspace Repository.', __CLASS__, $this->workspaceName), LOG_NOTICE);
        }
        if ($this->workspace !== null) {
            $this->validateWorkspace($this->workspace);
        }
        return $this->workspace;
    }

Usage Example

 /**
  * Tests addPathConstraintToQueryBuilder, see https://jira.neos.io/browse/NEOS-1849
  *
  * @test
  */
 public function findByPathWithoutReduceLimitsToRootNodeCorrectly()
 {
     $this->setUpNodes();
     $workspace = $this->context->getWorkspace();
     $foundNodes = $this->nodeDataRepository->findByPathWithoutReduce('/', $workspace, false, true);
     $this->assertCount(7, $foundNodes);
 }
All Usage Examples Of Neos\ContentRepository\Domain\Service\Context::getWorkspace