Code Monkey home page Code Monkey logo

cfgtokenlib's People

Contributors

alinilie avatar liutec avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cfgtokenlib's Issues

Chained token resolvers problem

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',
);

Implement access credentials request for URL 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.

Pass down token resolvers for xref src

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:

  1. open file a.json and load resolver1
  2. open file b.json and use resolver1 and load resolver2
  3. open file c.json and use resolver2
  4. attempt to open {x}/folder2/success.json and fail

Desired way of using resolvers when compiling:

  1. open file a.json and load resolver1
  2. open file b.json and use resolver1 and load resolver2
  3. open file c.json and use resolver2 then resolver1
  4. open folder1/folder2/success.json

Note that the desired algorithm should only apply when resolving tokens in the xref src NOT in the content.

Resolve file XRefs relative to current XRef src

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 CLI Token Resolver

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.