AppserverIo\Appserver\PersistenceContainer\BeanManager::attach PHP Метод

attach() публичный Метод

Attaches the passed bean, depending on it's type to the container.
public attach ( object $instance, string $sessionId = null ) : void
$instance object The bean instance to attach
$sessionId string The session-ID when we have stateful session bean
Результат void
    public function attach($instance, $sessionId = null)
    {
        // load the object manager
        $objectManager = $this->getApplication()->search(ObjectManagerInterface::IDENTIFIER);
        // load the bean descriptor
        $descriptor = $objectManager->getObjectDescriptors()->get(get_class($instance));
        // query if we've stateful session bean
        if ($descriptor instanceof StatefulSessionBeanDescriptorInterface) {
            // check if we've a session-ID available
            if ($sessionId == null) {
                throw new \Exception('Can\'t find a session-ID to attach stateful session bean');
            }
            // load the lifetime from the session bean settings
            $lifetime = $this->getManagerSettings()->getLifetime();
            // we've to check for pre-attach callbacks
            foreach ($descriptor->getPreAttachCallbacks() as $preAttachCallback) {
                $instance->{$preAttachCallback}();
            }
            // create a unique SFSB identifier
            $identifier = SessionBeanUtil::createIdentifier($sessionId, $descriptor->getClassName());
            // load the map with the SFSBs
            $sessionBeans = $this->getStatefulSessionBeans();
            // add the stateful session bean to the map
            $sessionBeans->add($identifier, $instance, $lifetime);
            // stop processing here
            return;
        }
        // query if we've stateless session or message bean
        if ($descriptor instanceof StatelessSessionBeanDescriptorInterface || $descriptor instanceof MessageDrivenBeanDescriptorInterface) {
            // simply destroy the instance
            $this->destroyBeanInstance($instance);
            // stop processing here
            return;
        }
        // query if we've singleton session bean
        if ($descriptor instanceof SingletonSessionBeanDescriptorInterface) {
            // we've to check for pre-attach callbacks
            foreach ($descriptor->getPreAttachCallbacks() as $preAttachCallback) {
                $instance->{$preAttachCallback}();
            }
            // stop processing here
            return;
        }
        // we've an unknown bean type => throw an exception
        throw new InvalidBeanTypeException('Tried to attach invalid bean type');
    }