AppserverIo\Appserver\Core\Api\AppService::newFromApplication PHP Method

newFromApplication() public method

Creates a new app node for the passed application and attaches it to the system configuration.
public newFromApplication ( AppserverIo\Psr\Application\ApplicationInterface $application ) : void
$application AppserverIo\Psr\Application\ApplicationInterface The application to create a new AppNode for
return void
    public function newFromApplication(ApplicationInterface $application)
    {
        // create a new AppNode and initialize it
        $appNode = new AppNode();
        $appNode->initFromApplication($application);
        $appNode->setParentUuid($this->getSystemConfiguration()->getUuid());
        // persist the AppNode instance
        $this->persist($appNode);
    }

Usage Example

Example #1
0
 /**
  * Will test if we can successfully add an app to the configuration based on a given application object
  *
  * @return null
  */
 public function testNewFromApplication()
 {
     // create a basic mock for our abstract service class
     $mockApp = $this->getMock('\\AppserverIo\\Psr\\Application\\ApplicationInterface');
     $mockApp->expects($this->once())->method('getName')->will($this->returnValue(__METHOD__));
     $this->appService->newFromApplication($mockApp);
     $apps = $this->appService->getSystemConfiguration()->getApps();
     $foundApp = false;
     foreach ($apps as $app) {
         if ($app->getName() === __METHOD__) {
             $foundApp = true;
             break;
         }
     }
     $this->assertTrue($foundApp);
 }