Exemple #1
0
        // Private Methods 

        private IEnumerable <IPhpStatement> ConvertDefinedConstToCode()
        {
            var result         = new List <IPhpStatement>();
            var alreadyDefined = new List <string>();

            if (!DefinedConsts.Any())
            {
                return(result.ToArray());
            }
            var grouped = DefinedConsts.GroupBy(u => GetNamespace(u.Key)).ToArray();

            var useNamespaces = grouped.Length > 1 || grouped[0].Key != PathUtil.UNIX_SEP;

            foreach (var group in grouped)
            {
                List <IPhpStatement> container;
                if (useNamespaces)
                {
                    var ns1 = new PhpNamespaceStatement((PhpNamespace)group.Key);
                    container = ns1.Code.Statements;
                    result.Add(ns1);
                }
                else
                {
                    container = result;
                }

                foreach (var item in group)
                {
                    var shortName = GetShortName(item.Key);
                    if (alreadyDefined.Contains(item.Key))
                    {
                        continue;
                    }
                    alreadyDefined.Add(item.Key);
                    var defined     = new PhpMethodCallExpression("defined", new PhpConstValue(shortName));
                    var notDefined  = new PhpUnaryOperatorExpression(defined, "!");
                    var define      = new PhpMethodCallExpression("define", new PhpConstValue(shortName), item.Value);
                    var ifStatement = new PhpIfStatement(notDefined, new PhpExpressionStatement(define), null);
                    container.Add(ifStatement);
                }
            }

            return(result.ToArray());
        }
Exemple #2
0
        // Private Methods 

        private IEnumerable<IPhpStatement> ConvertDefinedConstToCode()
        {
            var result = new List<IPhpStatement>();
            var alreadyDefined = new List<string>();
            if (!_definedConsts.Any()) return result.ToArray();
            var grouped = _definedConsts.GroupBy(u => GetNamespace(u.Key)).ToArray();

            var useNamespaces = grouped.Length > 1 || grouped[0].Key != PathUtil.UNIX_SEP;
            foreach (var group in grouped)
            {
                List<IPhpStatement> container;
                if (useNamespaces)
                {
                    var ns1 = new PhpNamespaceStatement((PhpNamespace)@group.Key);
                    container = ns1.Code.Statements;
                    result.Add(ns1);
                }
                else
                    container = result;
                foreach (var item in @group)
                {
                    var shortName = GetShortName(item.Key);
                    if (alreadyDefined.Contains(item.Key))
                        continue;
                    alreadyDefined.Add(item.Key);
                    var defined = new PhpMethodCallExpression("defined", new PhpConstValue(shortName));
                    var notDefined = new PhpUnaryOperatorExpression(defined, "!");
                    var define = new PhpMethodCallExpression("define", new PhpConstValue(shortName), item.Value);
                    var ifStatement = new PhpIfStatement(notDefined, new PhpExpressionStatement(define), null);
                    container.Add(ifStatement);
                }
            }
            return result.ToArray();
        }