Skip to content

Commit

Permalink
new luya config (#1952)
Browse files Browse the repository at this point in the history
* Update app-admin-module-assets.md

* ResponseCache using PageCache filter and mark $actionsCallable and
$actions as deprecated. #1827

* Update app-cmsproperties.md (#1828)

* Update app-cmsproperties.md

move comment

* Update app-cmsproperties.md

* Update app-cmsproperties.md

* Update app-admin-module.md (#1829)

* Add files via upload

* Update app-language.md

* Lazyload widget asset registration issue fixed when used in nested
context. closes #1830

* Create ngrest-api.md

* Update README.md

* Update ngrest-api.md

* Update ngrest-api.md

* Fixed issue with create url and complex composition patterns. #1831

* Update ngrest-api.md

* Update ngrest-api.md

* fix php doc

* add option for apiRules
luyadev/luya-module-admin#174

* Update app-translation.md

* Update app-translation.md

* Translation to English

* Update organisation.md

* Update organisation.md

* Update organisation.md

* Corrections. (#1836)

* Corrections.

* Update organisation.md

* Update organisation.md

* Update organisation.md

* make web bootstrap bc safe

* Update luya-package-dev.md

* Added new option `Composer::$hideDefaultPrefixOnly`  (#1834)

* Add `hideDefaultPrefixOnly` option

When enabled, composition prefixes will be hidden only for default language. Takes effect only when `hidden` option is disabled.

* Add Changelog record for `Composer::$hideDefaultPrefixOnly`

* Update app-translation.md

* Update app-translation.md

* Add `hideDefaultPrefixOnly` option

When enabled, composition prefixes will be hidden only for default language. Takes effect only when `hidden` option is disabled.

* Add Changelog record for `Composer::$hideDefaultPrefixOnly`

* add unit test

* Update CHANGELOG.md

* prepare release

* release bump

* remove comment

* api and headless update

* changed docs for new ActiveWindowFromWidget
luyadev/luya-module-admin#188

* Add body params to error report

* fix issue where only admin module is available and set as default route

* Update UPGRADE.md (#1839)

* auto convert mail message to alt body closes #1840

* Polish translation (#1841)

* Issue 1816 (#1843)

* View mapping for module action

* Unit Test for viewmapping

* Viewmap refactoring

* Viewpath refactoring

* Bugfix

* Changelog

* PHPdoc

* Translation Helper for dev (#1844)

* Translation helper controler

* PHPdoc

* PHPdoc

* Reformat

* Changelog #1844

* closes luyadev/luya-module-admin#185

* Fix issue where frontend rules have precedence over admin closes #1848

* cs fix and remove random aded char.

* prepare for release

* release bump

* add new truncate middle helper

* closes #1850, closes #1851

* Updated svg widget to enable svg > use implementation for svg sprites (#1852)

* Updated svg widget to enable svg > use implementation for svg sprites
* Added changelog entry; Added @SInCE tags

* add callable option for mock arguments closes #1853

* force cli env when applicationConsole is called #1856

* yii base object not available #1856

* Update organisation.md (#1858)

* Update app-module-urlrules.md

* Update app-module-urlrules.md

* Update app-module-urlrules.md

* docs and typos (closes #1812)

* update menu

* prepare for release

* bump release

* lock file update

* Update app-module-urlrules.md

* Update concept-depandsync.md (#1860)

* Update app-storage.md

* Update app-storage.md

* Update app-menu.md

* Update install-structures.md

* github markdown fixer

* Issue 1855 (#1861)

* Translation helper controler

* PHPdoc

* Unique url in Modul-Block context #1855

* Updated luya guideline GULP and CSS infos

* Updated Resources section

* Update luya-guideline.md

* Update app-module-urlrules.md

* Update app-module-urlrules.md

* fixed alt body cleanup closes #1859

* fixed alias use in renderLayout closes #1863

* Example for custom directives (#1865)

closes #1864

* Make ./luya serve command work out of the box (#1866)

Before:

```
$ ./luya serve
Document root "/home/cebe/dev/cebe.cc/luya/web" does not exist.
```

After:

```
$ ./luya serve
Server started on http://localhost:8080/
Document root is "/home/cebe/dev/cebe.cc/luya/public_html"
Quit the server with CTRL-C or COMMAND-C.

```

* add changelog #1866

* Update luya-package-dev.md

* Fix bug with word highlight in string helper. closes #1869

* prepare for release

* release bump

* Update luya-guideline.md

* string helper highlight word accepts list of words closes #1872

* string helper truncate middle no results output and strict compare closes #1870

* remove word highlight case sensitivity #1871

* Lazyload widget update (#1868)

* Initial update for base64 encode; Needs more work; #1867
* Updated widget
* Rewritten lazyload js and added new placeholderSrc. Updated lazyload docs; #1867
* Updated widget and documentation for better base64 usability; Added @SInCE tags; #1867
* Updated styles for placeholder div
* Fixed an issue that occurs if two types of lazyloading are used on one page
* Added package.json; Added Karma conf; Added first basic LazyLoad tests
* Update LazyLoad.php

* Updated LazyLoading to improve placeholder behaviour; Updated tests

* Fixed small issue with placeholder height

* Added LocalBusiness Json-Ld. Fixed Event Json-Ld, and TypeHinting. #1872

* add new schema org entries #1872

* remove empty values by default

* add new guide section for active buttons

* fix local business inheritance, rating, aggregate rating and postal address. #1872

* fix range issue

* Update app-storage.md

* use debug message isntead of info

* Extend guide "Admin permission" (#1873)

* Update app-storage.md (#1874)

*  Correct parameter order for help (#1875)

* Translation helper controler

* PHPdoc

* Correct parameter order for help

* Update RepoController.php

* change empty/null value handling

* update curl version constraint

* prepare for release

* bump version

* Update app-blocks.md

* Create app-admin-module-api.md

* Update README.md

* Update app-admin-module-api.md (#1880)

* Update app-admin-module-api.md

* Update app-admin-module-api.md

* Update app-admin-module-api.md

* Update app-admin-module-api.md

* Quote highlight word

* Update RangeValue.php

* Add requires.push info

liberosoft/luyawysiwyg#1

* Url module controller context fix (#1877)

* Translation helper controler

* PHPdoc

* Correct parameter order for help

* Bugfix with language switcher #1876

* Unit test fix

* Refactoring urlReplaceModule

* Changelog

* Typo

* Documentation for block preview  (#1884)

* Documentation for block preview luyadev/luya-module-cms#83

* Documentation for block preview luyadev/luya-module-cms#83

* change naming

* Update app-admin-module-dashboardobjects.md

* Update app-admin-module-dashboardobjects.md

* Updated lazyload: Added function refetchElements to force lazyload to handle new images (for example in async loaded content)

* LazyLoading: Small fix to prevent issues with adding new images to existing page

* LazyLoad: Fixed small issue with id/index

* closes #1888 closes #1887

* Changelog update; Closes #1889

* Fixed issue with lazyloading; #1889

* Fix issue where current url rule appends path param. closes #1885

* add originalArgs for request route

* add php 7.3

* allow php 7.3 to fail

* Correct a typing error (#1893)

* add email tag obfuscation #1895

* change unit tests, encoding ensure mailto

* fix html class name

* fix email tag obfuscation

* ensure obfuscation encoding #1895

* Update concept-depandsync.md

* PHPDoc correction (#1896)

Corrected class (changed from old deprecated to new Behavior)

* fix issue with yii constants closes #1897

* fix telephone link exception closes #1898

* Update Formatter.php (#1899)

Typo

* Fix Composition::createRouteEnsure (#1902)

* Fix Composition::createRouteEnsure

with hideDefaultPrefixOnly == true composition component should not hide lang code if current lang *is* default but the url being constructed *is not* (e.g. LanguageSwitcher)

* CHANGELOG entry

* fixed variable declaration and psr isset

* revert Yii include hirarchy #1897

* use basename for mail attachment closes #1900

* Update app-blocks.md

* refactor resolver #1905

* add $expectedValues for valid language testing #1905

* add not found catch in url manager #1905

* add active window buttons to doc

* Update install-upgrade.md

* Issue 1907 (#1908)

* add test case and new regex #1907

* add tag sub value escapeing #1907

* add changelog #1907

* Update TagParser.php

* prepare for release

* release bump

* Delete ISSUE_TEMPLATE.md

* Delete PULL_REQUEST_TEMPLATE.md

* Update luya-collaboration.md

* Fix StringHelper::highlightWord delimiter issue closes #1909

* Fixed resized callback in lazyload js; Closes #1910

* Update organisation.md

* Fixed bug in ArrayHelper::searchColumn() when using assoc arrays. closes #1911

* prepare for release

* prepare packages for semver

* use parent unlink class for file helper

* update git wrapper dependencies

* add new trait helper #1912

* fix regex issue with php 7.3

* add php 7.3

* add deprecated info

* fix robots filter session problem #1914

* change constraint

* remove fixed platform

* ignore platform requirements

* move to require dev

* use version 1 of git wrapper package

* fix robot filter bug

* ignore platform reqs

* add platform

* add robot tests

* merge variables

* change min requirement

* update lock file

* Update ngrest-plugins.md (#1915)

There is an mystype in renderList method

* change loader path finder

* use relative path for config in bin closes #1799

* Update luya-guideline.md

* Update ngrest-activewindow.md

* Update app-admin-module-assets.md

* Update app-admin-module-assets.md

* prepare for release

* add changelog section

* release bump

* Update install-upgrade.md

* Formating inproved (#1919)

* add resolveHostInfo #1921

* admin 2.0 draft

* Update note_admin-2.0.0.md

* Update note_admin-2.0.0.md

* use new ds seperator

* pools guide luyadev/luya-module-admin#236

* add images for admin 2.0 release note

* change image paths

* text updates

* Update note_admin-2.0.0.md (#1922)

* fixed issue with binary

* add notifications text draft

* update news

* prepare for release

* update lock file

* update changelog

* release bump

* allow git wrapper version 1

* Update install-upgrade.md

* add new object helpers #1925

* use static functions

* fix bug in fileToName method

* add new console command context check #1927

* use fix class path #1927

* Update luya-package-dev.md

* use code climate

* fixed issue with relativ links in link tag #1931

* add travis unit test verbosity

* ensure object helper method does not throw exceptio

* add invalid param exception to try catch block

* prepare for release

* release bump

* Update app-storage.md

* Update deploy file with best practises and example (#1934)

* Update deploy file with best practises and example

* Update concept-depandsync.md

* Update concept-depandsync.md

* add rest helper

* Update text on page properties (#1935)

* Update text on page properties

Some typo's, explanation on where to find these properties in the CMS part and code on how to use the properties in a view.

* Update app-cmsproperties.md

* Travis mysql connection failed (#1937)

* Translation helper controler

* PHPdoc

* Correct parameter order for help

* Documentation for block preview luyadev/luya-module-cms#83

* Revert PHP doc

* Travis mysql connection failed

* fix rest helper with static key word

* fix use statement

* add cleanHost and domain methods closes #1940

* add infos to error handler #1939

* filter empty array values

* check if file is empty

* add changelog closes #1941

* add subdomain test

* add php doc

* prepare changelog

* add test

* use setFrom() #1942

* version bump

* allow to extend composite auth methods

* Update install-problems.md

* add optional auth actions to rest behavior

* Update CHANGELOG.md

* Update ngrest-plugin-select.md

* Update ngrest-plugin-select.md

* Update ngrest-plugin-select.md

* Update ngrest-plugin-select.md

* Update ngrest-plugin-select.md

* add bootstrap, add changelog, add docs
  • Loading branch information
nadar authored Aug 27, 2019
1 parent 4e196d7 commit ac27f9a
Show file tree
Hide file tree
Showing 6 changed files with 811 additions and 123 deletions.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE

## 1.0.21

+ [#1772](https://github.com/luyadev/luya/issues/1772) Add new `luya\Config` to generate configuration builds depending on console or web runtime.
+ [#1950](https://github.com/luyadev/luya/issues/1950) Fixed bug in Export Helper when dealing with special chars.
+ [#1942](https://github.com/luyadev/luya/issues/1942) Use phpmailers `setFrom()` method instead of `$from` and `$fromName` property.
+ [#340|admin](https://github.com/luyadev/luya-module-admin/issues/340) Allow extending the auth methods in rest behavior trait.
Expand Down
318 changes: 318 additions & 0 deletions core/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
<?php

namespace luya;

use luya\helpers\ArrayHelper;

/**
* Configuration array Helper.
*
* The {{luya\Config}} allows you to create the configuration for different hosts and difference between web and console config.
*
* ```php
* $config = new Config('myapp', dirname(__DIR__), [
* 'siteTitle' => 'My LUYA Project',
* 'defaultRoute' => 'cms',
* // other application level configurations
* ]);
*
* // define global components which works either for console or web runtime
*
* $config->component('mail', [
* 'host' => 'xyz',
* 'from' => '[email protected]',
* ]);
*
* $config->component('db', [
* 'class' => 'yii\db\Connection',
* 'dsn' => 'mysql:host=localhost;dbname=prod_db',
* 'username' => 'foo',
* 'password' => 'bar',
* ]);
*
* // define components which are only for web or console runtime:
*
* $config->webComponent('request', [
* 'cookieValidationKey' => 'xyz',
* ]);
*
* // which is equals to, but the above is better to read and structure in the config file
*
* $config->component('request', [
* 'cookieValidationKey' => 'xyz',
* ])->webRuntime();
*
* // adding modules
*
* $config->module('admin', [
* 'class' => 'luya\admin\Module',
* 'secureLogin' => true,
* ]);
*
* $config->module('cms', 'luya\cms\frontend\Module'); // which is equals to $config->module('cms', ['class' => 'luya\cms\frontend\Module']);
*
* // export and generate the config for a given enviroment or environment independent.
*
* return $config->toArray(); // returns the config not taking care of enviroment variables like prod, env
*
* return $config->toArray(Config::ENV_PROD);
* ```
*
* Switching between envs can be usefull if certain configurations should only apply on a certain environment. Therefore you can add `env()` behind componenets, applications and modules.
*
* ```php
* $config->component('db', [
* 'class' => 'yii\db\Connection',
* 'dsn' => 'mysql:host=localhost;dbname=prod_db',
* 'username' => 'foo',
* 'password' => 'bar',
* ])->env(Config::ENV_LOCAL);
*
* $config->component('db', [
* 'class' => 'yii\db\Connection',
* 'dsn' => 'mysql:host=localhost;dbname=prod_db',
* 'username' => 'foo',
* 'password' => 'bar',
* ])->env(Config::ENV_DEV);
*
* $config->component('db', [
* 'class' => 'yii\db\Connection',
* 'dsn' => 'mysql:host=localhost;dbname=prod_db',
* 'username' => 'foo',
* 'password' => 'bar',
* ])->env(Config::ENV_PROD);
*
* return $config->toArray(Config::ENV_PROD); // would only return the prod env db component
* ```
*
* @author Basil Suter <[email protected]>
* @since 1.0.21
*/
class Config
{
const ENV_ALL = 'all';

const ENV_PROD = 'prod';

const ENV_PREP = 'prep';

const ENV_DEV = 'dev';

const ENV_LOCAL = 'local';

const RUNTIME_ALL = 0;

const RUNTIME_CONSOLE = 1;

const RUNTIME_WEB = 2;

/**
* Constructor
*
* @param string $id
* @param string $basePath
* @param array $applicationConfig
*/
public function __construct($id, $basePath, array $applicationConfig = [])
{
$applicationConfig['id'] = $id;
$applicationConfig['basePath'] = $basePath;
$this->application($applicationConfig);
}

/**
* register application level config
*
* @param array $config The array to configure
* @return ConfigDefinition
*/
public function application(array $config)
{
return $this->addDefinition(new ConfigDefinition(ConfigDefinition::GROUP_APPLICATIONS, md5(serialize($config)), $config));
}

/**
* Register one or more bootstrap entries into the bootstrap section.
*
* @param array $config An array with bootstrap entries, its common to use the module name
* @return ConfigDefinition
*/
public function bootstrap(array $config)
{
return $this->addDefinition(new ConfigDefinition(ConfigDefinition::GROUP_BOOTSTRAPS, md5(serialize($config)), $config));
}

/**
* Register a module.
*
* @param string $id The module identifier.
* @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property.
* @return ConfigDefinition
*/
public function module($id, $config)
{
return $this->addDefinition(new ConfigDefinition(ConfigDefinition::GROUP_MODULES, $id, $config));
}

/**
* Register a component
*
* @param string $id The id of the component
* @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property.
* @param string $runtime The runtime for the component: all, web or console
* @return ConfigDefinition
*/
public function component($id, $config, $runtime = self::RUNTIME_ALL)
{
return $this->addDefinition(new ConfigDefinition(ConfigDefinition::GROUP_COMPONENTS, $id, $config))->runtime($runtime);
}

/**
* Register a web runtime component.
*
* @param string $id The id of the component
* @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property.
* @return ConfigDefinition
*/
public function webComponent($id, $config)
{
return $this->component($id, $config, self::RUNTIME_WEB);
}

/**
* Register a console runtime component.
*
* @param string $id The id of the component
* @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property.
* @return ConfigDefinition
*/
public function consoleComponent($id, $config)
{
return $this->component($id, $config, self::RUNTIME_CONSOLE);
}

private $_definitions = [];

/**
* Add a defintion into the defintions bag.
*
* @param ConfigDefinition $definition
* @return ConfigDefinition
*/
private function addDefinition(ConfigDefinition $definition)
{
$this->_definitions[] = $definition;

return $definition;
}

private $_isCliRuntime;

/**
* Whether runtime is cli or not
*
* @return boolean
*/
public function isCliRuntime()
{
if ($this->_isCliRuntime === null) {
$this->_isCliRuntime = strtolower(php_sapi_name()) === 'cli';
}

return $this->_isCliRuntime;
}

/**
* Setter method for runtime.
*
* > This method is mainly used for unit testing.
*
* @param boolean $value
*/
public function setCliRuntime($value)
{
$this->_isCliRuntime = $value;
}

/**
* Export the given configuration as array for certain envs.
*
* @param array $envs A list of environments to export. if nothing is given all enviroments will be returned.
* @return array The configuration array
*/
public function toArray(array $envs = [])
{
$config = [];
$envs = array_merge($envs, [self::ENV_ALL]);
foreach ($this->_definitions as $definition) { /** @var ConfigDefinition $definition */
// validate if current export env is in the list of envs
if (!$definition->validateEnvs($envs)) {
continue;
}
// validate runtime circumstances
if ($definition->validateRuntime(self::RUNTIME_ALL)) {
$this->appendConfig($config, $definition);
} elseif ($this->isCliRuntime() && $definition->validateRuntime(self::RUNTIME_CONSOLE)) {
$this->appendConfig($config, $definition);
} elseif (!$this->isCliRuntime() && $definition->validateRuntime(self::RUNTIME_WEB)) {
$this->appendConfig($config, $definition);
}
}

return $config;
}

/**
* Append a given defintion int othe config
*
* @param array $config
* @param ConfigDefinition $definition
*/
private function appendConfig(&$config, ConfigDefinition $definition)
{
switch ($definition->getGroup()) {
case ConfigDefinition::GROUP_APPLICATIONS:
foreach ($definition->getConfig() as $k => $v) {
$config[$k] = $v;
}
break;
case ConfigDefinition::GROUP_COMPONENTS:
$this->handleKeyBaseMerge($config, $definition, 'components');
break;

case ConfigDefinition::GROUP_MODULES:
$this->handleKeyBaseMerge($config, $definition, 'modules');
break;

case ConfigDefinition::GROUP_BOOTSTRAPS:
if (!array_key_exists('bootstrap', $config)) {
$config['bootstrap'] = [];
}
foreach ($definition->getConfig() as $v) {
$config['bootstrap'][] = $v;
}
}
}

/**
* Add a array key based component defintion.
*
* @param array $config
* @param ConfigDefinition $definition
* @param string $section
*/
private function handleKeyBaseMerge(&$config, ConfigDefinition $definition, $section)
{
// ass missing section key
if (!array_key_exists($section, $config)) {
$config[$section] = [];
}

// if key exists, merge otherwise create key
if (isset($config[$section][$definition->getKey()])) {
$config[$section][$definition->getKey()] = ArrayHelper::merge($config[$section][$definition->getKey()], $definition->getConfig());
} else {
$config[$section][$definition->getKey()] = $definition->getConfig();
}
}
}
Loading

0 comments on commit ac27f9a

Please sign in to comment.