Rewrite config by transforming magicals to factories and invokables

@param array $config
494192
public function transformMagicals(array $config)
    {
        if (isset($config['magicals'])) {
            foreach ($config['magicals'] as $magical) {
                if (isset($config['services'][$magical])) {
                    continue;
                }
                if (! isset($config['factories'][$magical])) {
                    $factory = $magical . 'Factory';
                    if (class_exists($factory)) {
                        $config['factories'][$magical] = $factory;
                        continue;
                    }
                    if (! isset($config['invokables'][$magical]) && class_exists($magical)) {
                        $config['invokables'][$magical] = $magical;
                    }
                }
            }
        }
        return $config;
    }
1155939
protected function prepareConfig(array $config)
    {
        $config = new Config($config);
        $config->setFallback($this->getConfig());

        return $config;
    }
318182
protected function applyAssignConfig(array $config) : void
    {
        $this->assignRoles(ArrayHelper::get($config, 'roles', []));
        $this->assignPermissions(ArrayHelper::get($config, 'permissions', []));
    }
918499
static public function setConfig(array $config)
    {
        foreach ($config as $k => $v) {
            self::$_config[$k] = $v;
        }
    }
131933
public function initialize(array $config)
    {
        parent::initialize($config);

        $_config = [
            'context'  => __d('core', 'record'),
            'redirect' => [
                'action'     => 'index',
                'prefix'     => $this->_request->getParam('prefix'),
                'plugin'     => $this->_request->getParam('plugin'),
                'controller' => $this->_request->getParam('controller'),
            ],
            'messages' => [
                'no_action' => __d('core', 'Action not found.'),
                'no_choose' => __d('core', 'Please choose only one item.'),
            ]
        ];

        $config = Hash::merge($_config, $config);
        $this->setConfig($config);
    }
123254
private function __buildConfig(array $config)
    {
        foreach ($config as $key => $conf) {
            if ($key == 'driver') {
                $this->rawConfig['type'] = strtolower($conf);
                continue;
            }

            if (!array_key_exists($key, $this->rawConfig)) {
                $this->error->setMessage(sprintf(
                    "invalid config '%s', allowed config are: %s",
                    $key, implode(', ', array_keys($this->rawConfig))
                ));
                break;
            }

            $this->rawConfig[$key] = $conf;
        }

        if (!$this->error->hasError() && !$this->hasDriver($this->getType()) && !$this->preventNoLocalDriver) {
            $this->error->setMessage(sprintf(
                "Driver '%s' not available. Please choose one of: '%s'. ".
                'Or register new ConnectionString class by implements %s.',
                $this->getType(),
                implode("', '", $this->getAvailableDrivers()),
                ConnectionStringInterface::class
            ));
        }
    }
1057711
public function setConfig(array $config)
    {
        foreach ($this->configurable as $setting) {
            if ( ! isset($config[$setting])) {
                continue;
            }

            $method = 'set' . ucfirst($setting);

            if (method_exists($this, $method)) {
                $this->$method($config[$setting]);
            }
        }

        return $this;
    }
92391
public function applyConfig(array $config = []) {
        $parent = $this;
        $defaults = isset($this->_config) ? $this->_config : [];

        // Inherit config from parents
        while ($parent = get_parent_class($parent)) {
            $props = get_class_vars($parent);

            if (isset($props['_config'])) {
                $defaults = Hash::merge($props['_config'], $defaults);
            }
        }

        $this->__config = new ConfigAugment($config, $defaults);

        return $this;
    }
891453
public function transform($config)
    {
        array_walk($config, function(&$value, $key) {
            if (in_array($key, $this->getKeys(), true)) {
                $value = $this->transformValue($value);
            } else {
                if ($this->shouldRecurse($value, $key)) {
                    $value = $this->transform($value);
                }
            }
        });

        return $config;
    }
671390
public static function createFromConfig(array $config)
    {
        $manager = static::createEmptyFromConfig($config);

        $manager->addCollection(new CssCollection)
                ->addCollection(new JavascriptCollection);

        return $manager;
       
    }
1081219
public static function factory($config = array()) {
        $default = array(
            'serverUrls' => null,
            'user' => null,
            'publicKey' => null,
            'privateKey' => null,
        );

        // Backwards-compatibility with old client where user === publicKey
        if (!isset($config['user']) && isset($config['publicKey'])) {
            $config['user'] = $config['publicKey'];
        }

        $required = array('serverUrls', 'publicKey', 'privateKey', 'user');
        $config = Collection::fromConfig($config, $default, $required);

        if (!is_array($serverUrls = $config->get('serverUrls')) || empty($serverUrls)) {
            throw new InvalidArgumentException('serverUrls must be an array');
        }

        // Create the client and attach the service description
        return new self($serverUrls[0], $config);
    }
768815
public static function configure(array $config)
    {
        if (!is_null(static::$instance)) {
            return static::$instance;
        }

        static::$config = $config;

        static::$session = Session::getInstance();

        return static::$instance = new Auth($config[$config['default']]);
    }
125023
protected function prepareMockConfig(array &$config = [])
    {
        if (!isset($config['willReturn'])) {
            $config['willReturn'] = [];
        }

        if (!empty($config['methods']) && is_array($config['methods'])) {
            $methodNames = [];
            foreach ($config['methods'] as $key => $value) {
                $methodNames[] = is_numeric($key) ? $value : $key;
                if (!is_numeric($key)) {
                    $config['willReturn'][$key] = $value;
                }
            }
            $config['methods'] = $methodNames;
        }

        if (!isset($config['will'])) {
            $config['will'] = [];
        }

        if(isset($config['constructor'], $config['disableOriginalConstructor'])) {
            unset($config['constructor']);
        }

        if (isset($config['constructor'])) {
            $config['disableOriginalConstructor'] = !$config['constructor'];
            unset($config['constructor']);
        }
    }
237295
public function configure($config)
    {
        foreach ((array)$config as $key => $value) {
            $this->setConfig($key, $value);
        }
    }
73102
protected function configureMachine(array $config)
	{
		// Load simple config options
		$this->loadMachineConfig($config, ['table', 'table_alias', 'state_select', 'filters']);

		// Properties (unless set before)
		if ($this->properties === null) {
			if (empty($config['properties'])) {
				// Scan database for properties if not specified
				$this->scanTableColumns();
			}
		}

		// Setup machine. Properties may be set before initializing,
		// this will merge config with autodetected properties
		parent::configureMachine($config);

		// Collect primary key from properties
		if ($this->pk_columns === null) {
			$this->pk_columns = array();
			foreach ($this->properties as $property => $p) {
				if (!empty($p['is_pk'])) {
					$this->pk_columns[] = $property;
				}
			}
		}

		// Check for primary key
		if (empty($this->pk_columns)) {
			throw new InvalidArgumentException('Primary key is missing in table '.var_export($this->table, true));
		}

		// Prepare list of composed properties and encoded columns
		$this->composed_properties = array();
		$this->json_columns = array();
		foreach ($this->properties as $property => $p) {
			if (!empty($p['components'])) {
				$this->composed_properties[$property] = $p['components'];
			}
			if (isset($p['column_encoding']) && $p['column_encoding'] == 'json') {
				$this->json_columns[] = $property;
			}
		}
	}
249758
public function initialize(array $config = []) {
		$config = $this->_config;

		if (empty($config['bits'])) {
			$config['bits'] = Inflector::variable(Inflector::pluralize($config['field']));
		}

		$entity = $this->_table->newEntity();

		if (is_callable($config['bits'])) {
			$config['bits'] = call_user_func($config['bits']);
		} elseif (is_string($config['bits']) && method_exists($entity, $config['bits'])) {
			$method = $config['bits'];
			$config['bits'] = version_compare(PHP_VERSION, '7.0', '<') ? $entity->$method() : $entity::$method();
		} elseif (is_string($config['bits']) && method_exists($this->_table, $config['bits'])) {
			$table = $this->_table;
			$method = $config['bits'];
			$config['bits'] = version_compare(PHP_VERSION, '7.0', '<') ? $table->$method() : $table::$method();
		} elseif (!is_array($config['bits'])) {
			$config['bits'] = false;
		}
		if (empty($config['bits'])) {
			$method = Inflector::variable(Inflector::pluralize($config['field'])) . '()';
			throw new RuntimeException('Bits not found for field ' . $config['field'] . ', expected pluralized static method ' . $method . ' on the entity.');
		}
		ksort($config['bits'], SORT_NUMERIC);

		$this->_config = $config;
	}
951933
private function configure(array $config = []): void
    {
        foreach ($config as $param => $value) {
            $property = $this->toCamelCase($param);
            if (property_exists(self::class, $property)) {
                $this->$property = $value;
            }
        }
    }