public function registerClasses(Definition $prototype, $namespace, $resource, $exclude = null)
    {
        if ('\\' !== substr($namespace, -1)) {
            throw new InvalidArgumentException(sprintf('Namespace prefix must end with a "\\": %s.', $namespace));
        }
        if (!preg_match('/^(?:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+\\\\)++$/', $namespace)) {
            throw new InvalidArgumentException(sprintf('Namespace is not a valid PSR-4 prefix: %s.', $namespace));
        }

        $classes = $this->findClasses($namespace, $resource, (array) $exclude);
        // prepare for deep cloning
        $serializedPrototype = serialize($prototype);
        $interfaces = [];
        $singlyImplemented = [];

        foreach ($classes as $class => $errorMessage) {
            if (interface_exists($class, false)) {
                $interfaces[] = $class;
            } else {
                $this->setDefinition($class, $definition = unserialize($serializedPrototype));
                if (null !== $errorMessage) {
                    $definition->addError($errorMessage);

                    continue;
                }
                foreach (class_implements($class, false) as $interface) {
                    $singlyImplemented[$interface] = isset($singlyImplemented[$interface]) ? false : $class;
                }
            }
        }
        foreach ($interfaces as $interface) {
            if (!empty($singlyImplemented[$interface])) {
                $this->container->setAlias($interface, $singlyImplemented[$interface])
                    ->setPublic(false);
            }
        }
    }
public function registerClasses(Definition $prototype, $namespace, $resource, $exclude = null)
    {
        if ('\\' !== substr($namespace, -1)) {
            throw new InvalidArgumentException(sprintf('Namespace prefix must end with a "\\": %s.', $namespace));
        }
        if (!preg_match('/^(?:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+\\\\)++$/', $namespace)) {
            throw new InvalidArgumentException(sprintf('Namespace is not a valid PSR-4 prefix: %s.', $namespace));
        }

        $classes = $this->findClasses($namespace, $resource, (array) $exclude);
        // prepare for deep cloning
        $serializedPrototype = serialize($prototype);
        $interfaces = [];
        $singlyImplemented = [];

        foreach ($classes as $class => $errorMessage) {
            if (interface_exists($class, false)) {
                $interfaces[] = $class;
            } else {
                $this->setDefinition($class, $definition = unserialize($serializedPrototype));
                if (null !== $errorMessage) {
                    $definition->addError($errorMessage);

                    continue;
                }
                foreach (class_implements($class, false) as $interface) {
                    $singlyImplemented[$interface] = isset($singlyImplemented[$interface]) ? false : $class;
                }
            }
        }
        foreach ($interfaces as $interface) {
            if (!empty($singlyImplemented[$interface])) {
                $this->container->setAlias($interface, $singlyImplemented[$interface])
                    ->setPublic(false);
            }
        }
    }
public function registerClasses ( Definition $ prototype , $ namespace , $ resource , $ exclude = null ) { if ( '\\' !== substr ( $ namespace , - 1 ) ) { throw new InvalidArgumentException ( sprintf ( 'Namespace prefix must end with a "\\": %s.' , $ namespace ) ) ; } if ( ! preg_match ( '/^(?:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+\\\\)++$/' , $ namespace ) ) { throw new InvalidArgumentException ( sprintf ( 'Namespace is not a valid PSR-4 prefix: %s.' , $ namespace ) ) ; } $ classes = $ this -> findClasses ( $ namespace , $ resource , ( array ) $ exclude ) ; // prepare for deep cloning $ serializedPrototype = serialize ( $ prototype ) ; $ interfaces = [ ] ; $ singlyImplemented = [ ] ; foreach ( $ classes as $ class => $ errorMessage ) { if ( interface_exists ( $ class , false ) ) { $ interfaces [ ] = $ class ; } else { $ this -> setDefinition ( $ class , $ definition = unserialize ( $ serializedPrototype ) ) ; if ( null !== $ errorMessage ) { $ definition -> addError ( $ errorMessage ) ; continue ; } foreach ( class_implements ( $ class , false ) as $ interface ) { $ singlyImplemented [ $ interface ] = isset ( $ singlyImplemented [ $ interface ] ) ? false : $ class ; } } } foreach ( $ interfaces as $ interface ) { if ( ! empty ( $ singlyImplemented [ $ interface ] ) ) { $ this -> container -> setAlias ( $ interface , $ singlyImplemented [ $ interface ] ) -> setPublic ( false ) ; } } }
Registers a set of classes as services using PSR-4 for discovery.

@param Definition           $prototype A definition to use as template
@param string               $namespace The namespace prefix of classes in the scanned directory
@param string               $resource  The directory to look for classes, glob-patterns allowed
@param string|string[]|null $exclude   A globbed path of files to exclude or an array of globbed paths of files to exclude
Registers a set of classes as services using PSR - 4 for discovery .