AcMailer\Controller\Plugin\Factory\SendMailPluginAbstractFactory::canCreate PHP Method

canCreate() public method

Determine if we can create a service with name
public canCreate ( Interop\Container\ContainerInterface $container, $requestedName ) : boolean
$container Interop\Container\ContainerInterface
$requestedName
return boolean
    public function canCreate(ContainerInterface $container, $requestedName)
    {
        /** @var ControllerPluginManager $serviceLocator */
        if (strpos($requestedName, 'sendMail') !== 0) {
            return false;
        }
        if ($requestedName === 'sendMail') {
            return true;
        }
        $specificServiceName = $this->getSpecificServiceName($requestedName);
        return array_key_exists($specificServiceName, $this->getConfig($container));
    }

Usage Example

 public function testCanCreateServiceWhenConcreteServiceIsNotDefined()
 {
     $sm = $this->createServiceManager(['acmailer_options' => ['concrete' => []]]);
     $this->assertTrue($this->factory->canCreate($sm, 'sendMailConcrete'));
     $this->assertFalse($this->factory->canCreate($sm, 'sendMailInvalid'));
 }