text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = void 0;
  
  var _Definition = _interopRequireDefault(require("./Definition"));
  
  var _PassConfig = _interopRequireDefault(require("./PassConfig"));
  
  var _Compiler = _interopRequireDefault(require("./Compiler"));
  
  var _CompilerPass = _interopRequireDefault(require("./CompilerPass"));
  
  var _InstanceManager = _interopRequireDefault(require("./InstanceManager"));
  
  var _DefinitionNotFoundException = _interopRequireDefault(require("./Exception/DefinitionNotFoundException"));
  
  var _LoadMethodNotFoundException = _interopRequireDefault(require("./Exception/LoadMethodNotFoundException"));
  
  var _LoggerWarnMethodNotFoundException = _interopRequireDefault(require("./Exception/LoggerWarnMethodNotFoundException"));
  
  var _WrongDefinitionException = _interopRequireDefault(require("./Exception/WrongDefinitionException"));
  
  var _FrozenContainerException = _interopRequireDefault(require("./Exception/FrozenContainerException"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  
  function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  var ContainerBuilder = /*#__PURE__*/function () {
    /**
     * @param {boolean} containerReferenceAsService
     * @param {String} defaultDir
     */
    function ContainerBuilder() {
      var containerReferenceAsService = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
      var defaultDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  
      _classCallCheck(this, ContainerBuilder);
  
      this._definitions = new Map();
      this._parameters = new Map();
      this._alias = new Map();
      this._container = new Map();
      this._frozen = false;
      this._compilerPass = new _CompilerPass["default"](this);
      this._extensions = [];
      this._logger = console;
      this._instanceManager = undefined;
      this._containerReferenceAsService = containerReferenceAsService;
      this._defaultDir = defaultDir;
    }
    /**
     * @returns {String}
     */
  
  
    _createClass(ContainerBuilder, [{
      key: "defaultDir",
      get: function get() {
        return this._defaultDir;
      }
      /**
       * @returns {boolean}
       */
  
    }, {
      key: "containerReferenceAsService",
      get: function get() {
        return this._containerReferenceAsService;
      }
      /**
       * @returns {Map}
       */
  
    }, {
      key: "definitions",
      get: function get() {
        return this._definitions;
      }
      /**
       * @returns {boolean}
       */
  
    }, {
      key: "frozen",
      get: function get() {
        return this._frozen;
      }
      /**
       * @param {boolean} value
       */
      ,
      set: function set(value) {
        this._frozen = value;
      }
      /**
       * @return {InstanceManager}
       */
  
    }, {
      key: "instanceManager",
      get: function get() {
        if (!this._instanceManager) {
          this._instanceManager = new _InstanceManager["default"](this, this._definitions, this._alias);
        }
  
        return this._instanceManager;
      }
      /**
       * @returns {Array}
       */
  
    }, {
      key: "extensions",
      get: function get() {
        return this._extensions;
      }
      /**
       * @returns {Console|*}
       */
  
    }, {
      key: "logger",
      get: function get() {
        return this._logger;
      }
      /**
       * @param {Console|*} value
       */
      ,
      set: function set(value) {
        if (typeof value.warn !== 'function') {
          throw new _LoggerWarnMethodNotFoundException["default"]();
        }
  
        this._logger = value;
      }
      /**
       * @return {Map}
       */
  
    }, {
      key: "services",
      get: function get() {
        return this._container;
      }
      /**
       * @param {string} id
       * @param {*|null} object
       * @param {Array} args
       * @returns {Definition}
       */
  
    }, {
      key: "register",
      value: function register(id) {
        var object = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
        var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  
        if (!this.frozen) {
          var definition = new _Definition["default"]();
          definition.Object = object;
          definition.args = args;
  
          if (!object) {
            definition.synthetic = true;
          }
  
          return this.setDefinition(id, definition);
        }
  
        throw new _FrozenContainerException["default"]();
      }
      /**
       * @param {string} id
       */
  
    }, {
      key: "get",
      value: function get(id) {
        return this.instanceManager.getInstance(id);
      }
    }, {
      key: "compile",
      value: function compile() {
        new _Compiler["default"](this).run();
      }
      /**
       * @param {*} compilerPass
       * @param {string} type
       * @param {number} priority
       */
  
    }, {
      key: "addCompilerPass",
      value: function addCompilerPass(compilerPass) {
        var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _PassConfig["default"].TYPE_BEFORE_OPTIMIZATION;
        var priority = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  
        this._compilerPass.register(compilerPass, type, priority);
      }
      /**
       * @param {string} alias
       * @param {string} id
       */
  
    }, {
      key: "setAlias",
      value: function setAlias(alias, id) {
        this._alias.set(alias, id);
      }
      /**
       * @param {string} id
       * @param {Definition} definition
       * @returns {Definition}
       */
  
    }, {
      key: "setDefinition",
      value: function setDefinition(id, definition) {
        if (definition instanceof _Definition["default"]) {
          this._definitions.set(id, definition);
  
          return definition;
        }
  
        throw new _WrongDefinitionException["default"]();
      }
      /**
       * @param {string} name
       * @returns {Map}
       */
  
    }, {
      key: "findTaggedServiceIds",
      value: function findTaggedServiceIds(name) {
        var taggedServices = new Map();
  
        var _iterator = _createForOfIteratorHelper(this._definitions),
            _step;
  
        try {
          for (_iterator.s(); !(_step = _iterator.n()).done;) {
            var _step$value = _slicedToArray(_step.value, 2),
                id = _step$value[0],
                definition = _step$value[1];
  
            if (definition.tags.some(function (tag) {
              return tag.name === name;
            })) {
              taggedServices.set(id, definition);
            }
          }
        } catch (err) {
          _iterator.e(err);
        } finally {
          _iterator.f();
        }
  
        return taggedServices;
      }
      /**
       * @param {string} key
       * @param {string||Array|boolean|Object} value
       */
  
    }, {
      key: "setParameter",
      value: function setParameter(key, value) {
        if (typeof value !== 'string' && !Array.isArray(value) && typeof value !== 'boolean' && _typeof(value) !== 'object') {
          throw new TypeError('The expected value is not a flat string, an array, a boolean or an object');
        }
  
        this._parameters.set(key, value);
      }
      /**
       * @param {string} key
       * @returns {string|Array}
       */
  
    }, {
      key: "getParameter",
      value: function getParameter(key) {
        return this._parameters.get(key);
      }
      /**
       * @param {string} key
       * @returns {boolean}
       */
  
    }, {
      key: "hasParameter",
      value: function hasParameter(key) {
        return this._parameters.has(key);
      }
      /**
       * @param {string} key
       * @returns {boolean}
       */
  
    }, {
      key: "hasDefinition",
      value: function hasDefinition(key) {
        return this._definitions.has(key);
      }
      /**
       * @param {string} key
       * @returns {boolean}
       */
  
    }, {
      key: "has",
      value: function has(key) {
        return this._definitions.has(key) || this._parameters.has(key) || this._alias.has(key);
      }
      /**
       * @param {string} method
       * @param {string} key
       * @returns {Definition|boolean}
       * @private
       */
  
    }, {
      key: "_definition",
      value: function _definition(method, key) {
        if (this._definitions.has(key)) {
          return this._definitions[method](key);
        }
  
        throw new _DefinitionNotFoundException["default"](key);
      }
      /**
       * @param {string} key
       * @returns {Definition}
       */
  
    }, {
      key: "getDefinition",
      value: function getDefinition(key) {
        return this._definition('get', key);
      }
      /**
       * @param {string} key
       * @returns {boolean}
       */
  
    }, {
      key: "removeDefinition",
      value: function removeDefinition(key) {
        return this._definition('delete', key);
      }
      /**
       * @param {string} key
       * @returns {Definition}
       */
  
    }, {
      key: "findDefinition",
      value: function findDefinition(key) {
        key = this._alias.get(key) || key;
  
        if (this._definitions.has(key)) {
          return this._definitions.get(key);
        }
  
        throw new _DefinitionNotFoundException["default"](key);
      }
      /**
       * @param {*} extension
       */
  
    }, {
      key: "registerExtension",
      value: function registerExtension(extension) {
        if (typeof extension.load !== 'function') {
          throw new _LoadMethodNotFoundException["default"](extension.constructor.name);
        }
  
        this._extensions.push(extension);
      }
      /**
       * @param {string} id
       * @param {*} instance
       */
  
    }, {
      key: "set",
      value: function set(id, instance) {
        this._container.set(id, instance);
      }
      /**
       * @param {string} id
       */
  
    }, {
      key: "remove",
      value: function remove(id) {
        this._container["delete"](id);
      }
      /**
       * @param {string} id
       * @returns {boolean}
       */
  
    }, {
      key: "isSet",
      value: function isSet(id) {
        return this._container.has(id);
      }
    }]);
  
    return ContainerBuilder;
  }();
  
  var _default = ContainerBuilder;
  exports["default"] = _default;