src/Eloquent/Typhoon/Configuration/ConfigurationReader.php
protected function readComposer($path)
    {
        $this->typeCheck->readComposer(func_get_args());

        $composerPath = $this->composerPath($path);
        if (!$this->isolator->is_file($composerPath)) {
            return null;
        }

        $composerData = $this->composerReader()->read($composerPath);
        if (
            $composerData->extra() instanceof stdClass &&
            property_exists($composerData->extra(), 'typhoon') &&
            $composerData->extra()->typhoon instanceof stdClass
        ) {
            $typhoonData = $composerData->extra()->typhoon;
        } else {
            $typhoonData = new stdClass;
        }

        if (!property_exists($typhoonData, ConfigurationOption::SOURCE_PATHS()->value())) {
            $sourcePaths = $composerData->allSourcePaths();

            if (!property_exists($typhoonData, ConfigurationOption::OUTPUT_PATH()->value())) {
                $typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()} = $this->inferOutputPath(
                    $sourcePaths
                );
            }

            $typhoonData->{ConfigurationOption::SOURCE_PATHS()->value()} = array();
            foreach ($sourcePaths as $sourcePath) {
                if (!$this->pathIsDescandantOrEqual(
                    $path,
                    $typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()},
                    $sourcePath
                )) {
                    $typhoonData->{ConfigurationOption::SOURCE_PATHS()->value()}[] = $sourcePath;
                }
            }
        } elseif (!property_exists($typhoonData, ConfigurationOption::OUTPUT_PATH()->value())) {
            $typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()} = $this->inferOutputPath(
                $typhoonData->{ConfigurationOption::SOURCE_PATHS()->value()}
            );
        }

        if (!property_exists($typhoonData, ConfigurationOption::VALIDATOR_NAMESPACE()->value())) {
            $validatorNamespace = array_search(
                array($typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()}),
                $composerData->autoloadPSR0(),
                true
            );

            if (false === $validatorNamespace) {
                $mainNamespace = null;
                $mainNamespaceLength = null;
                foreach ($composerData->autoloadPSR0() as $namespace => $paths) {
                    $namespaceLength = count(explode('\\', $namespace));
                    if (
                        null === $mainNamespace ||
                        $namespace < $mainNamespaceLength
                    ) {
                        $mainNamespace = $namespace;
                        $mainNamespaceLength = $namespaceLength;
                    }
                }

                if (null !== $mainNamespace) {
                    $typhoonData->{ConfigurationOption::VALIDATOR_NAMESPACE()->value()} =
                        sprintf('%s\\TypeCheck', $mainNamespace)
                    ;
                }
            } else {
                $typhoonData->{ConfigurationOption::VALIDATOR_NAMESPACE()->value()} =
                    $validatorNamespace
                ;
            }
        }

        if (!property_exists($typhoonData, ConfigurationOption::USE_NATIVE_CALLABLE()->value())) {
            $composerDependencies = $composerData->dependencies();
            $phpConstraint = null;
            if (array_key_exists('php', $composerDependencies)) {
                $phpConstraint = $composerDependencies['php'];
            } elseif (array_key_exists('php-64bit', $composerDependencies)) {
                $phpConstraint = $composerDependencies['php-64bit'];
            }

            $useNativeCallable = false;
            if (null !== $phpConstraint) {
                foreach (explode(',', $phpConstraint) as $constraint) {
                    if (
                        preg_match('/>=?\s*(\d+(?:\.\d+)?(?:\.\d+)?)/', $constraint, $matches) &&
                        version_compare($matches[1], '5.4', '>=')
                    ) {
                        $useNativeCallable = true;
                    }
                }
            }

            $typhoonData->{ConfigurationOption::USE_NATIVE_CALLABLE()->value()} =
                $useNativeCallable
            ;
        }

        return $this->buildConfiguration($typhoonData);
    }
protected function readComposer($path)
    {
        $this->typeCheck->readComposer(func_get_args());

        $composerPath = $this->composerPath($path);
        if (!$this->isolator->is_file($composerPath)) {
            return null;
        }

        $composerData = $this->composerReader()->read($composerPath);
        if (
            $composerData->extra() instanceof stdClass &&
            property_exists($composerData->extra(), 'typhoon') &&
            $composerData->extra()->typhoon instanceof stdClass
        ) {
            $typhoonData = $composerData->extra()->typhoon;
        } else {
            $typhoonData = new stdClass;
        }

        if (!property_exists($typhoonData, ConfigurationOption::SOURCE_PATHS()->value())) {
            $sourcePaths = $composerData->allSourcePaths();

            if (!property_exists($typhoonData, ConfigurationOption::OUTPUT_PATH()->value())) {
                $typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()} = $this->inferOutputPath(
                    $sourcePaths
                );
            }

            $typhoonData->{ConfigurationOption::SOURCE_PATHS()->value()} = array();
            foreach ($sourcePaths as $sourcePath) {
                if (!$this->pathIsDescandantOrEqual(
                    $path,
                    $typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()},
                    $sourcePath
                )) {
                    $typhoonData->{ConfigurationOption::SOURCE_PATHS()->value()}[] = $sourcePath;
                }
            }
        } elseif (!property_exists($typhoonData, ConfigurationOption::OUTPUT_PATH()->value())) {
            $typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()} = $this->inferOutputPath(
                $typhoonData->{ConfigurationOption::SOURCE_PATHS()->value()}
            );
        }

        if (!property_exists($typhoonData, ConfigurationOption::VALIDATOR_NAMESPACE()->value())) {
            $validatorNamespace = array_search(
                array($typhoonData->{ConfigurationOption::OUTPUT_PATH()->value()}),
                $composerData->autoloadPSR0(),
                true
            );

            if (false === $validatorNamespace) {
                $mainNamespace = null;
                $mainNamespaceLength = null;
                foreach ($composerData->autoloadPSR0() as $namespace => $paths) {
                    $namespaceLength = count(explode('\\', $namespace));
                    if (
                        null === $mainNamespace ||
                        $namespace < $mainNamespaceLength
                    ) {
                        $mainNamespace = $namespace;
                        $mainNamespaceLength = $namespaceLength;
                    }
                }

                if (null !== $mainNamespace) {
                    $typhoonData->{ConfigurationOption::VALIDATOR_NAMESPACE()->value()} =
                        sprintf('%s\\TypeCheck', $mainNamespace)
                    ;
                }
            } else {
                $typhoonData->{ConfigurationOption::VALIDATOR_NAMESPACE()->value()} =
                    $validatorNamespace
                ;
            }
        }

        if (!property_exists($typhoonData, ConfigurationOption::USE_NATIVE_CALLABLE()->value())) {
            $composerDependencies = $composerData->dependencies();
            $phpConstraint = null;
            if (array_key_exists('php', $composerDependencies)) {
                $phpConstraint = $composerDependencies['php'];
            } elseif (array_key_exists('php-64bit', $composerDependencies)) {
                $phpConstraint = $composerDependencies['php-64bit'];
            }

            $useNativeCallable = false;
            if (null !== $phpConstraint) {
                foreach (explode(',', $phpConstraint) as $constraint) {
                    if (
                        preg_match('/>=?\s*(\d+(?:\.\d+)?(?:\.\d+)?)/', $constraint, $matches) &&
                        version_compare($matches[1], '5.4', '>=')
                    ) {
                        $useNativeCallable = true;
                    }
                }
            }

            $typhoonData->{ConfigurationOption::USE_NATIVE_CALLABLE()->value()} =
                $useNativeCallable
            ;
        }

        return $this->buildConfiguration($typhoonData);
    }
protected function readComposer ( $ path ) { $ this -> typeCheck -> readComposer ( func_get_args ( ) ) ; $ composerPath = $ this -> composerPath ( $ path ) ; if ( ! $ this -> isolator -> is_file ( $ composerPath ) ) { return null ; } $ composerData = $ this -> composerReader ( ) -> read ( $ composerPath ) ; if ( $ composerData -> extra ( ) instanceof stdClass && property_exists ( $ composerData -> extra ( ) , 'typhoon' ) && $ composerData -> extra ( ) -> typhoon instanceof stdClass ) { $ typhoonData = $ composerData -> extra ( ) -> typhoon ; } else { $ typhoonData = new stdClass ; } if ( ! property_exists ( $ typhoonData , ConfigurationOption :: SOURCE_PATHS ( ) -> value ( ) ) ) { $ sourcePaths = $ composerData -> allSourcePaths ( ) ; if ( ! property_exists ( $ typhoonData , ConfigurationOption :: OUTPUT_PATH ( ) -> value ( ) ) ) { $ typhoonData -> { ConfigurationOption :: OUTPUT_PATH ( ) -> value ( ) } = $ this -> inferOutputPath ( $ sourcePaths ) ; } $ typhoonData -> { ConfigurationOption :: SOURCE_PATHS ( ) -> value ( ) } = array ( ) ; foreach ( $ sourcePaths as $ sourcePath ) { if ( ! $ this -> pathIsDescandantOrEqual ( $ path , $ typhoonData -> { ConfigurationOption :: OUTPUT_PATH ( ) -> value ( ) } , $ sourcePath ) ) { $ typhoonData -> { ConfigurationOption :: SOURCE_PATHS ( ) -> value ( ) } [ ] = $ sourcePath ; } } } elseif ( ! property_exists ( $ typhoonData , ConfigurationOption :: OUTPUT_PATH ( ) -> value ( ) ) ) { $ typhoonData -> { ConfigurationOption :: OUTPUT_PATH ( ) -> value ( ) } = $ this -> inferOutputPath ( $ typhoonData -> { ConfigurationOption :: SOURCE_PATHS ( ) -> value ( ) } ) ; } if ( ! property_exists ( $ typhoonData , ConfigurationOption :: VALIDATOR_NAMESPACE ( ) -> value ( ) ) ) { $ validatorNamespace = array_search ( array ( $ typhoonData -> { ConfigurationOption :: OUTPUT_PATH ( ) -> value ( ) } ) , $ composerData -> autoloadPSR0 ( ) , true ) ; if ( false === $ validatorNamespace ) { $ mainNamespace = null ; $ mainNamespaceLength = null ; foreach ( $ composerData -> autoloadPSR0 ( ) as $ namespace => $ paths ) { $ namespaceLength = count ( explode ( '\\' , $ namespace ) ) ; if ( null === $ mainNamespace || $ namespace < $ mainNamespaceLength ) { $ mainNamespace = $ namespace ; $ mainNamespaceLength = $ namespaceLength ; } } if ( null !== $ mainNamespace ) { $ typhoonData -> { ConfigurationOption :: VALIDATOR_NAMESPACE ( ) -> value ( ) } = sprintf ( '%s\\TypeCheck' , $ mainNamespace ) ; } } else { $ typhoonData -> { ConfigurationOption :: VALIDATOR_NAMESPACE ( ) -> value ( ) } = $ validatorNamespace ; } } if ( ! property_exists ( $ typhoonData , ConfigurationOption :: USE_NATIVE_CALLABLE ( ) -> value ( ) ) ) { $ composerDependencies = $ composerData -> dependencies ( ) ; $ phpConstraint = null ; if ( array_key_exists ( 'php' , $ composerDependencies ) ) { $ phpConstraint = $ composerDependencies [ 'php' ] ; } elseif ( array_key_exists ( 'php-64bit' , $ composerDependencies ) ) { $ phpConstraint = $ composerDependencies [ 'php-64bit' ] ; } $ useNativeCallable = false ; if ( null !== $ phpConstraint ) { foreach ( explode ( ',' , $ phpConstraint ) as $ constraint ) { if ( preg_match ( '/>=?\s*(\d+(?:\.\d+)?(?:\.\d+)?)/' , $ constraint , $ matches ) && version_compare ( $ matches [ 1 ] , '5.4' , '>=' ) ) { $ useNativeCallable = true ; } } } $ typhoonData -> { ConfigurationOption :: USE_NATIVE_CALLABLE ( ) -> value ( ) } = $ useNativeCallable ; } return $ this -> buildConfiguration ( $ typhoonData ) ; }
@param string $path

@return Configuration|null
@param string $path