Substitute the placeholder {tcp_port} and {base_dir}
from a config array.

@param array<string, mixed> $configArray associative array
@param int|string           $port

@return array<string, mixed>
3920
protected function substitutePlaceholders(array $configArray, $port): array
    {
        $substituted = [];
        $base_dir = $this->getBaseDir();

        foreach ($configArray as $key => $value) {
            $tmp = str_replace('{base_dir}', $base_dir, $value);
            $tmp = str_replace('{tcp_port}', (string) $port, $tmp);
            $substituted[$key] = $tmp;
        }

        return $substituted;
    }
990706
private static function getHostAndPortFromHost($host): array
    {
        if (\is_array($host)) {
            $host = \implode(', ', $host);
        }

        $port = null;

        // works for regname, IPv4 & IPv6
        if (\preg_match('|\:(\d+)$|', $host, $matches)) {
            $host = \substr($host, 0, -1 * (\strlen($matches[1]) + 1));
            $port = (int) $matches[1];
        }

        return [$host, $port];
    }
1357714
private static function createContainerConfigList(array $conf, bool $debug, float $startedAt){
        return array_merge(
            [new ContainerConfig\AppConfig($debug)],
            $conf,
            [
                new ContainerConfig\TraitConfig(),
                new ContainerConfig\TypeConfig(),
                new ContainerConfig\ActionConfig(),
                new ContainerConfig\MiddlewareConfig()
            ],
            $debug ? [new ContainerConfig\DebugConfig($startedAt)] : [],
            [new ContainerConfig\CoreConfig()]
        );
    }
1047376
public function withPort($port): URI
    {
        $result = clone $this;
        $result->port = $this->filterPort($port);

        return $result;
    }
24977
public function port($port = null)
    {
        if (func_num_args() === 1) {
            $this->_port = $port;
            return $this;
        }
        if ($this->_port !== null) {
            return $this->_port;
        }
        $scheme = $this->_classes['scheme'];
        $name = $this->scheme();

        if ($scheme::registered($name)) {
            return $scheme::port($name);
        }
    }
588058
protected function filterPort($port)
    {
        if (is_null($port) || (is_integer($port) && ($port >= 1 && $port <= 65535))) {
            return $port;
        }

        throw new InvalidArgumentException('Uri port must be null or an integer between 1 and 65535 (inclusive)');
    }
252198
public static function fromArray($array)
    {
        $isRemote     = isset($array['remote']) || isset($array['remote_value']);
        $isRemoteProp = $isRemote && !isset($array['remote_value']);

        if ($isRemote) {
            if ($isRemoteProp) {
                $value = $array['remote'];
            } else {
                $value = $array['remote_value'];
            }
            $property = $array['local'];
        } else {
            $value    = $array['value'];
            $property = $array['property'];
        }

        if (!(isset($value, $property))) {
            throw new DcGeneralInvalidArgumentException('Invalid filter array provided  ' . \var_export($array, true));
        }

        return new static($property, $value, $isRemote, $isRemoteProp);
    }
1216180
public static function createTransport($transport, array $config)
    {
        $config = new Structure($config);

        switch ($transport) {
            case 'smtp':
                $instance = \Swift_SmtpTransport::newInstance(
                    $config->get('smtp.host'),
                    $config->get('smtp.port', 2525),
                    $config->get('smtp.security', 'tls')
                )->setUsername($config->get('smtp.username'))
                    ->setPassword($config->get('smtp.password'));

                if ($config->get('smtp.local')) {
                    $instance->setLocalDomain($config->get('local'));
                }

                if (!$config->get('smtp.verify', true)) {
                    $instance->setStreamOptions(['ssl' => ['allow_self_signed' => true, 'verify_peer' => false]]);
                }

                break;

            case 'sendmail':
                $instance = \Swift_SendmailTransport::newInstance($config->get('sendmail'));

                break;

            default:
                $instance = \Swift_MailTransport::newInstance();
        }

        return $instance;
    }
524232
public function setPort($port)
    {
        if (intval($port) <= 0) {
            throw new \InvalidArgumentException(sprintf('Invalid port: %d', $port));
        }

        $this->port = intval($port);

        return $this;
    }
1164620
protected function setHost($host, $port = null)
    {
        $this->host = $host;
        if ($port !== null) {
            if (is_numeric($port)) {
                $this->port = (int) $port;
            } else {
                throw new ConfigurationException("Port '{$port}' is not numeric");
            }
        }
    }
53961
public static function baseUrl($joinPort = true)
    {
        $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
        return $protocol . self::host($joinPort);
    }
183714
protected static function normalizePort(?int $port, ?string $scheme): ?int
    {
        if ($port === null) {
            return null;
        }

        if ($scheme && isset(static::$defaultPorts[$scheme]) && ($port == static::$defaultPorts[$scheme])) {
            return null;
        }

        return $port;
    }
941419
protected function filterPort($port)
    {
        if ($port !== null) {
            $port = intval($port);

            if ($port < 1 || $port > 65535) {
                throw new InvalidArgumentException(sprintf('Invalid port "%s".', $port));
            }
        } else {
            $port = null;
        }

        return $port;
    }
819238
public function configureFilesystemAdapter(ContainerBuilder $container, array $config)
    {
        // add the default configuration for the local filesystem
        if ($container->hasDefinition('sonata.media.adapter.filesystem.local') && isset($config['filesystem']['local'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.local')
                ->addArgument($config['filesystem']['local']['directory'])
                ->addArgument($config['filesystem']['local']['create'])
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.local');
        }

        // add the default configuration for the FTP filesystem
        if ($container->hasDefinition('sonata.media.adapter.filesystem.ftp') && isset($config['filesystem']['ftp'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.ftp')
                ->addArgument($config['filesystem']['ftp']['directory'])
                ->addArgument($config['filesystem']['ftp']['host'])
                ->addArgument([
                    'port' => $config['filesystem']['ftp']['port'],
                    'username' => $config['filesystem']['ftp']['username'],
                    'password' => $config['filesystem']['ftp']['password'],
                    'passive' => $config['filesystem']['ftp']['passive'],
                    'create' => $config['filesystem']['ftp']['create'],
                    'mode' => $config['filesystem']['ftp']['mode'],
                ])
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.ftp');
            $container->removeDefinition('sonata.media.filesystem.ftp');
        }

        // add the default configuration for the S3 filesystem
        if ($container->hasDefinition('sonata.media.adapter.filesystem.s3') && isset($config['filesystem']['s3'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.s3')
                ->replaceArgument(0, new Reference('sonata.media.adapter.service.s3'))
                ->replaceArgument(1, $config['filesystem']['s3']['bucket'])
                ->replaceArgument(2, ['create' => $config['filesystem']['s3']['create'], 'region' => $config['filesystem']['s3']['region'], 'directory' => $config['filesystem']['s3']['directory'], 'ACL' => $config['filesystem']['s3']['acl']])
            ;

            $container->getDefinition('sonata.media.metadata.amazon')
                ->addArgument([
                        'acl' => $config['filesystem']['s3']['acl'],
                        'storage' => $config['filesystem']['s3']['storage'],
                        'encryption' => $config['filesystem']['s3']['encryption'],
                        'meta' => $config['filesystem']['s3']['meta'],
                        'cache_control' => $config['filesystem']['s3']['cache_control'],
                ])
            ;

            if (3 === $config['filesystem']['s3']['sdk_version']) {
                $arguments = [
                    'region' => $config['filesystem']['s3']['region'],
                    'version' => $config['filesystem']['s3']['version'],
                ];

                if (isset($config['filesystem']['s3']['secretKey'], $config['filesystem']['s3']['accessKey'])) {
                    $arguments['credentials'] = [
                        'secret' => $config['filesystem']['s3']['secretKey'],
                        'key' => $config['filesystem']['s3']['accessKey'],
                    ];
                }

                $container->getDefinition('sonata.media.adapter.service.s3')
                    ->replaceArgument(0, $arguments)
                ;
            } else {
                $container->getDefinition('sonata.media.adapter.service.s3')
                    ->replaceArgument(0, [
                        'secret' => $config['filesystem']['s3']['secretKey'],
                        'key' => $config['filesystem']['s3']['accessKey'],
                    ])
                ;
            }
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.s3');
            $container->removeDefinition('sonata.media.filesystem.s3');
        }

        if ($container->hasDefinition('sonata.media.adapter.filesystem.replicate') && isset($config['filesystem']['replicate'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.replicate')
                ->replaceArgument(0, new Reference($config['filesystem']['replicate']['master']))
                ->replaceArgument(1, new Reference($config['filesystem']['replicate']['slave']))
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.replicate');
            $container->removeDefinition('sonata.media.filesystem.replicate');
        }

        if ($container->hasDefinition('sonata.media.adapter.filesystem.mogilefs') && isset($config['filesystem']['mogilefs'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.mogilefs')
                ->replaceArgument(0, $config['filesystem']['mogilefs']['domain'])
                ->replaceArgument(1, $config['filesystem']['mogilefs']['hosts'])
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.mogilefs');
            $container->removeDefinition('sonata.media.filesystem.mogilefs');
        }

        if ($container->hasDefinition('sonata.media.adapter.filesystem.opencloud') &&
            (isset($config['filesystem']['openstack']) || isset($config['filesystem']['rackspace']))) {
            if (isset($config['filesystem']['openstack'])) {
                $container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\OpenStack');
                $settings = 'openstack';
            } else {
                $container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\Rackspace');
                $settings = 'rackspace';
            }
            $container->getDefinition('sonata.media.adapter.filesystem.opencloud.connection')
                ->replaceArgument(0, $config['filesystem'][$settings]['url'])
                ->replaceArgument(1, $config['filesystem'][$settings]['secret'])
                ;
            $container->getDefinition('sonata.media.adapter.filesystem.opencloud')
                ->replaceArgument(1, $config['filesystem'][$settings]['containerName'])
                ->replaceArgument(2, $config['filesystem'][$settings]['create_container']);
            $container->getDefinition('sonata.media.adapter.filesystem.opencloud.objectstore')
                ->replaceArgument(1, $config['filesystem'][$settings]['region']);
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.opencloud');
            $container->removeDefinition('sonata.media.adapter.filesystem.opencloud.connection');
            $container->removeDefinition('sonata.media.adapter.filesystem.opencloud.objectstore');
            $container->removeDefinition('sonata.media.filesystem.opencloud');
        }
    }
77448
public function port($port = NULL)
	{
		if ($port !== NULL)
		{
			$this->_port = $port;
			return $this;
		}

		if ( ! $this->_port)
		{
			$this->_port = Network::ephimeral_port($this->host(), 4445, 5000);
		}

		return $this->_port;
	}
680481
public static function convertStringToValueArray(array $array): array
    {

        foreach ($array as $i => $attr)
            $array[$i] = (is_array($attr) ? self::convertStringToValueArray($attr) : self::convertStringToValues($attr));

        return $array;
    }
1118906
public function setPort($port)
    {
        if (!empty($port)) {
            $this->port = intval($port);
        }
        else {
            $this->port = null;
        }

        return $this;
    }