emagtechlabs / cfgtokenlib Goto Github PK
View Code? Open in Web Editor NEWConfiguration Token Resolver & Injector Library written in PHP.
License: MIT License
Configuration Token Resolver & Injector Library written in PHP.
License: MIT License
The following code does not produce the expected result:
$xrefDep1 = new Xref('file', 'dep1.json');
$xrefDep1->setData(
array(
'a' => '[[{{inner}}:token]]',
'[[{{inner}}:token]]' => 'b',
)
)->setResolved(true);
$xrefMain = new Xref('file', 'main.json');
$xrefMain->setData(
array(
'include' => array(
'xref' => array(
'dep1' => array(
'type' => 'file',
'src' => 'dep1.json',
'resolve' => array(
array(
'type' => 'registered',
'options' => array(
'token-prefix' => '{{',
'token-suffix' => '}}',
),
'values' => array(
'inner' => 'outer',
),
),
array(
'type' => 'registered',
'options' => array(
'token-prefix' => '[[',
'token-suffix' => ']]',
),
'values' => array(
'outer:token' => 'value',
),
),
),
),
),
'main' => array(
'dep1',
),
),
)
)->setResolved(true);
$treeCompiler = new TreeCompiler();
$treeCompiler->getXrefs()->add($xrefDep1);
$compiled = $treeCompiler->compileXref($xrefMain);
$expected = array(
'a' => 'value',
'value' => 'b',
);
Tokens should also be resolved in the "src" for "xrefs"
If content-type
is application/json
and HTTP Code 401 received when fetching the content of an URL XRef, assume that the content is JSON and has the following structure:
{
"cli": {
"message": "Enter your credentials", (optional, default "Authentication required")
"request": {
"<variable_name>": {
"prompt": "Enter <variable_name>", (optional, default "Enter variable_name")
"type": "string/password", (optional, default string)
"default": "value" (optional, default empty)
}
},
"order": [
"<variable_name>"
]
}
}
Ask the user to enter each requested variable in the specified order.
After the user has entered all requested variables, post them back as JSON encoded to the XRef's URL. (eg. {"<variable_name>": "value"}
If the "request" key is empty, assume fetching has failed.
When compiling, the token resolvers from the parent should be appended to the current token resolvers so that tokens in the src of the include chain may be properly resolved when needed, not when bubbling up as it is done for content.
eg.
file: a.json: include src:"b.json" resolver1: {x} with "folder1"
file: b.json: include src:"c.json" resolver2: {y} with "folder2"
file: c.json: include src:"{x}/{y}/d.json"
file folder1/folder2/success.json
Current way of using resolvers when compiling:
Desired way of using resolvers when compiling:
Note that the desired algorithm should only apply when resolving tokens in the xref src NOT in the content.
Implement a method to return an array of all token names within a token collection.
Update:
lib/ConfigToken/TreeCompiler/XrefResolver/Types/AbstractXrefResolver.php
lib/ConfigToken/TreeCompiler/XrefResolver/Types/LocalFileXrefResolver.php
lib/ConfigToken/TreeCompiler/XrefResolver/XrefResolverInterface.php
lib/ConfigToken/TreeCompiler/Xref.php
lib/ConfigToken/TreeCompiler.php
to consider file XRef src as relative to the latest local file include path.
Implement a new token resolver to extend ConfigToken\TokenResolver\Types\RegisteredTokenResolver and allow users to enter values for either the specified tokens or for all unresolved tokens.
The static method get
always returns the same instance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.