/*
@private function onlyFunctions (middleware)
Ensures that everything in the `middleware` Array
is, in fact, a function.
773737
function onlyFunctions(middleware) {
  if (!middleware || !Array.isArray(middleware)) {
    return [];
  }

  return middleware.filter(function (fn) {
    return typeof fn === 'function';
  });
}
988551
function bindFunctions(functions) {
	var _this = this;

	functions.forEach(function (f) {
		return _this[f] = _this[f].bind(_this);
	});
}
1097166
function(middlewares, method, request, response_middlewares, callback) {
        var that = this;
        try {
            var middleware = middlewares.shift();
            if (!middleware) {
                return this._makeRequest(request, callback, response_middlewares);
            }
            if (middleware.cond(method, request)) {
                var middleware_callback = function(retVal) {
                    /**
                     * got an error
                     * break middleware chain and callback
                     */
                    if (retVal && retVal instanceof Error) {
                        return callback(retVal, null);
                    }
                    /**
                     * got a response object
                     * break middleware chain and bypass request
                     */
                    if (retVal && typeof retVal == 'object') {
                        return that._callResponseMiddlewares(response_middlewares, retVal, callback);
                    }
                    /**
                     * got a callback
                     * push it on response_middlewares array
                     * will be called after request
                     */
                    if (retVal && typeof retVal == 'function') {
                        response_middlewares.unshift(retVal);
                    }
                    that._callRequestMiddlewares(middlewares, method, request, response_middlewares, callback);
                };
                middleware.fun(method, request, middleware_callback);
            } else {
                this._callRequestMiddlewares(middlewares, method, request, response_middlewares, callback);
            }
        } catch (e) {
            callback(e, null);
        }
    }
836979
function promesso (handler) {
  const handleFn = isFunction(handler) ? [handler] : handler;
  const middlewares = [];
  let validations = 0;

  handleFn.forEach(h => {
    if (!isFunction(h)) throw new Error('Handler is expected to be a function or an Array of functions.');

    if (isObject(handleFn['@validation'])) {
      middlewares.push(validation(h['@validation']), validationMiddleware);
      if (++validations > 1) throw new Error('Every handler can have only one validator per chain.');
    }

    middlewares.push(h);
  });

  return middlewares.map(rawOrPromise);
}
390434
function (/**Array|Object*/tmpl, /**Object*/data) /**String*/{
            var res= "";
            // there are thre possible declarations array of functions, string and function
            // array case
            if (franky.isArray(tmpl)) {
                res = franky.map(tmpl, function (item) {
                    return typeof item === "string" ?
                        item:
                        item(data);
                }).join("");
            // function case
            } else if (franky.isFunction(tmpl)) {
                res = tmpl(data);
            // default string case
            } else {
                res = tmpl.toString();
            }

            return res;
        }
641060
private function isFunction(array &$functions, array &$token, array &$previousToken)
    {
        return !empty($functions[$token[1]])
        && $previousToken[0] != \T_NAMESPACE
        && $previousToken[0] != \T_OBJECT_OPERATOR;
    }
56554
function isFunctionPromiseable(_thisObject, name, fn) {
     if (/Sync$/.test(name)) {
          return typeof _thisObject[ name.substring(0, name.length - 4) ] === "function";
     } else {
          return typeof _thisObject[ name + "Sync" ] === "function";
     }
}
190615
function(/* funs */) {
      var funs = arguments;

      return function(/* args */) {
        var args = arguments;
        return _.map(funs, function(f) {
          return f.apply(this, args);
        }, this);
      };
    }
465305
function (array, callback) {
    for (var len = 0; len < array.length; len++) {
      if (callback(array[len]) === false) {
        return false
      }
    }
    return true
  }
262734
function(array, fn) {
        if (typeof array.map == "function") {
          return array.map(fn);
        } else {
          var r = [];
          var l = array.length;
          for(var i = 0; i < l; i++) {
            r.push(fn(array[i]));
          }
          return r;
        }
      }
434643
function all(func) {
        return function() {
            var params = getParams(arguments);
            var length = params.length;
            for (var i = 0; i < length; i++) {
                if (!func.call(null, params[i])) {
                    return false;
                }
            }
            return true;
        };
    }
977307
function(a) {
    var fn = function(n, src, got, all) {
      if (n === 0) {
        all.push(got);
        return;
      }

      for (var j = 0; j < src.length; j++) {
        fn(n - 1, src.slice(j + 1), got.concat([src[j]]), all);
      }
    };

    var excluded = excludedPlugins.map(function(plugin) {
      return 'plugins/' + plugin + '.js';
    });

    // Remove the plugins that we don't want to build
    a = a.filter(function(n) {
      return excluded.indexOf(n) === -1;
    });

    var all = [a];

    for (var i = 0; i < a.length; i++) {
      fn(i, a, [], all);
    }

    return all;
  }
870073
function arrays() {
		extend(Array, {
			every: function every(array, fun, thisp) {
				var res = true,
					len = array.length >>> 0;
				for (var i = 0; i < len; i++) {
					if (array[i] !== undefined) {
						if (!fun.call(thisp, array[i], i, array)) {
							res = false;
							break;
						}
					}
				}
				return res;
			},
			forEach: function forEach(array, fun, thisp) {
				var len = array.length >>> 0;
				for (var i = 0; i < len; i++) {
					if (array[i] !== undefined) {
						fun.call(thisp, array[i], i, array);
					}
				}
			},
			map: function map(array, fun, thisp) {
				var m = [],
					len = array.length >>> 0;
				for (var i = 0; i < len; i++) {
					if (array[i] !== undefined) {
						m.push(fun.call(thisp, array[i], i, array));
					}
				}
				return m;
			},
			filter: function map(array, fun, thisp) {
				return Array.prototype.filter.call(array, fun, thisp);
			},
			isArray: function isArray(o) {
				return Object.prototype.toString.call(o) === "[object Array]";
			},
			concat: function(a1, a2) {
				function map(e) {
					return e;
				}
				return this.map(a1, map).concat(this.map(a2, map));
			}
		});
	}
940326
function proxy(func){
    'use strict';

    // Returns a middleware
    return function (kontx, next){
        func(kontx.args).then(
            function(payload){
                kontx.payload = payload;
                next();
            },
            function(err){
                next(err);
            }
        );
    };
}
1198540
function(handler, priority) {
        if(typeof handler !== 'function') {
          throw new Error('Middleware must be a function.');
        }

        if(typeof priority !== 'undefined') handler.priority = priority;
        _layerList.push(handler);
        return _inst;
      }
395516
function exclude(obj, keys) {
        var result, key;
        result = {};
        keys = keys || [];
        for (key in obj) {
            if (obj.hasOwnProperty(key)) {
                if (keys.indexOf(key) === -1) {
                    if (typeof obj[key] !== 'function') {
                        result[key] = obj[key];
                    }
                }
            }
        }
        return result;
    }
573636
function compose(middlewares, options = {}) {
  const { beforeRunMiddleware } = options;// before invoking the middleware, check whether can be run

  // all middleware should be function
  if (!Array.isArray(middlewares)) middlewares = [middlewares];
  for (const mw of middlewares) {
    if (typeof mw !== 'function') throw new TypeError('middleware should be a function');
  }

  return function ComposedMiddleware(req, resp, next) {
    let doRunMiddleware;

    let lastIndex = -1;// last run middleware index
    const runMiddleware = (index) => {
      if (lastIndex >= index) {
        return Promise.reject(new Error('next() called multiple times'));
      }
      lastIndex = index;

      const middleware = middlewares[index];
      if (middleware && beforeRunMiddleware) {
        return Promise.resolve(beforeRunMiddleware(middleware, req, resp)).then((canRun) => {
          if (!canRun) return runMiddleware(index + 1);
          else return doRunMiddleware(index);
        });
      }

      return doRunMiddleware(index);
    };

    doRunMiddleware = (index) => {
      let middleware = middlewares[index];
      const nextIndex = index + 1;

      let runNextMiddleware = noop;
      if (!middleware) {
        if (next) middleware = next;
      } else if (middlewares[nextIndex] || next) {
        runNextMiddleware = () => runMiddleware(nextIndex);
      }

      try {
        let result;
        if (middleware) result = middleware.call(this, req, resp, runNextMiddleware);
        return Promise.resolve(result);
      } catch (e) {
        return Promise.reject(e);
      }
    };

    return runMiddleware(0);
  };
}