AppserverIo\Appserver\Core\Api\AbstractService::getBaseDirectory PHP Method

getBaseDirectory() public method

Returns the application servers base directory.
public getBaseDirectory ( string | null $directoryToAppend = null ) : string
$directoryToAppend string | null Append this directory to the base directory before returning it
return string The base directory
    public function getBaseDirectory($directoryToAppend = null)
    {
        // load the base directory from the system configuration
        $baseDirectory = $this->getSystemConfiguration()->getBaseDirectory();
        // if a directory has been passed, make it absolute and append it
        if ($directoryToAppend != null) {
            $baseDirectory .= $this->makePathAbsolute($directoryToAppend);
        }
        // return the base directory, with the passed path appended
        return $baseDirectory;
    }

Usage Example

 /**
  * Tests the returning of a base directory without appending anything
  *
  * @return null
  */
 public function testGetBaseDirectoryNothingToAppend()
 {
     $baseDir = $this->service->getBaseDirectory();
     $this->assertEquals('/opt/appserver', $baseDir);
     $this->assertNotEquals('/opt/appserver/test/directory', $baseDir);
 }