/** * Factory method to create a new container instance. * * @param \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer The application instance to register the class loader with * @param \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $configuration The class loader configuration * * @return void */ public static function factory(ApplicationServerInterface $applicationServer, ContainerNodeInterface $configuration) { // create a new reflection class instance $reflectionClass = new \ReflectionClass($configuration->getType()); // initialize the container configuration with the base directory and pass it to the thread $params = array($applicationServer->getInitialContext(), $applicationServer->getNamingDirectory(), $configuration); // create and append the thread instance to the internal array return $reflectionClass->newInstanceArgs($params); }
/** * Factory method to create a new container instance. * * @param \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer The application instance to register the class loader with * @param \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $configuration The class loader configuration * @param integer $runlevel The runlevel the container has been started in * * @return void */ public static function factory(ApplicationServerInterface $applicationServer, ContainerNodeInterface $configuration, $runlevel = ApplicationServerInterface::NETWORK) { // create a new reflection class instance $reflectionClass = new \ReflectionClass($configuration->getType()); // initialize the container configuration with the base directory and pass it to the thread $params = array($applicationServer->getInitialContext(), $applicationServer->getNamingDirectory(), $configuration, $applicationServer->runlevelToString($runlevel)); // create, initialize and return the container instance return $reflectionClass->newInstanceArgs($params); }
/** * Creates a new scanner instance and attaches it to the passed server instance. * * @param \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $server The server instance to add the scanner to * @param \AppserverIo\Appserver\Core\Api\Node\ScannerNodeInterface $scannerNode The scanner configuration * * @return object The scanner instance */ public static function visit(ApplicationServerInterface $server, ScannerNodeInterface $scannerNode) { // load the initial context instance /** @var \AppserverIo\Appserver\Application\Interfaces\ContextInterface $initialContext */ $initialContext = $server->getInitialContext(); // load the reflection class for the scanner type $reflectionClass = new \ReflectionClass($scannerNode->getType()); // prepare the scanner params $scannerParams = array($initialContext, $scannerNode->getName()); $scannerParams = array_merge($scannerParams, $scannerNode->getParamsAsArray()); // register and start the scanner as daemon $server->bindService(ApplicationServerInterface::DAEMON, $reflectionClass->newInstanceArgs($scannerParams)); }
/** * Creates a new scanner instance and attaches it to the passed server instance. * * @param \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $server The server instance to add the scanner to * @param \AppserverIo\Appserver\Core\Api\Node\ScannerNodeInterface $scannerNode The scanner configuration * * @return object The scanner instance */ public static function visit(ApplicationServerInterface $server, ScannerNodeInterface $scannerNode) { // load the initial context instance /** @var \AppserverIo\Appserver\Application\Interfaces\ContextInterface $initialContext */ $initialContext = $server->getInitialContext(); // iterate over the configured directories and create a scanner instance for each of them /** @var \AppserverIo\Appserver\Core\Api\Node\DirectoryNodeInterface $directoryNode */ foreach ($scannerNode->getDirectories() as $directoryNode) { // load the reflection class for the scanner type $reflectionClass = new \ReflectionClass($scannerNode->getType()); // prepare the unique scanner name $scannerName = sprintf('%s-%s', $scannerNode->getName(), $directoryNode->getNodeValue()->__toString()); // prepare the scanner params $scannerParams = array($initialContext, $scannerName, $directoryNode->getNodeValue()->__toString()); $scannerParams = array_merge($scannerParams, $scannerNode->getParamsAsArray()); // register and start the scanner as daemon $server->bindService(ApplicationServerInterface::DAEMON, $reflectionClass->newInstanceArgs($scannerParams)); } }
/** * Creates a new singleton application server instance. * * @param \AppserverIo\Psr\Naming\NamingDirectoryInterface $configurationFilename The default naming directory * @param \AppserverIo\Storage\GenericStackable $runlevels The storage for the services * * @return \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface The singleton application instance */ public static function singleton(NamingDirectoryInterface $namingDirectory, GenericStackable $runlevels) { // query whether we already have an instance or not if (ApplicationServer::$instance == null) { // initialize and start the application server ApplicationServer::$instance = new ApplicationServer($namingDirectory, $runlevels); ApplicationServer::$instance->start(); } // return the instance return ApplicationServer::$instance; }