Exemplo n.º 1
0
        /// <summary>
        /// Helper method
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public static IPhpValue ConcatStrings(params IPhpValue[] items)
        {
            if (items == null)
            {
                return(null);
            }
            IPhpValue result = null;

            foreach (var i in items)
            {
                if (result == null)
                {
                    result = i;
                }
                else
                {
                    result = new PhpBinaryOperatorExpression(".", result, i);
                }
            }
            if (result != null)
            {
                var simplifier = new ExpressionSimplifier(new OptimizeOptions());
                result = simplifier.Simplify(result);
            }
            return(result);
        }
Exemplo n.º 2
0
        private void UpdateIncludePathExpression()
        {
            if (_assemblyInfo == null)
            {
                PhpIncludePathExpression = null;
                return;
            }
            var pathItems = new List <IPhpValue>();

            {
                var assemblyPath = _assemblyInfo.PhpIncludePathExpression;
                if (assemblyPath != null)
                {
                    pathItems.Add(assemblyPath);
                }
            }
            if (_optionalIncludePathPrefix != null && _optionalIncludePathPrefix.Any())
            {
                foreach (var n in _optionalIncludePathPrefix)
                {
                    if (n.StartsWith("$"))
                    {
                        pathItems.Add(new PhpVariableExpression(n, PhpVariableKind.Global));
                    }
                    else
                    {
                        pathItems.Add(new PhpDefinedConstExpression(n, null));
                    }
                }
            }
            pathItems.Add(new PhpConstValue(_name + Extension));
            PhpIncludePathExpression = PhpBinaryOperatorExpression.ConcatStrings(pathItems.ToArray());
        }
Exemplo n.º 3
0
 public IPhpValue MakeIncludePath(PhpCodeModuleName relatedTo)
 {
     if (relatedTo.Library == Library)
     {
         var knownPath = ProcessPath(_name + _extension, relatedTo._name + _extension);
         //dirname(__FILE__)
         var __FILE__ = new PhpDefinedConstExpression("__FILE__", null);
         var dirname  = new PhpMethodCallExpression("dirname", __FILE__);
         var path     = new PhpConstValue(PathUtil.MakeUnixPath(PathUtil.UNIX_SEP + knownPath));
         var result   = PhpBinaryOperatorExpression.ConcatStrings(dirname, path);
         return(result);
     }
     else
     {
         string path      = null;
         string pathRelTo = null;
         if (_phpIncludePathExpression is PhpConstValue)
         {
             path = (_phpIncludePathExpression as PhpConstValue).Value as string;
             if (path == null)
             {
                 throw new NotSupportedException();
             }
         }
         else
         {
             return(_phpIncludePathExpression); // assume expression like MPDF_LIB_PATH . 'lib/mpdf/mpdf.php'
         }
         if (relatedTo._phpIncludePathExpression is PhpConstValue)
         {
             pathRelTo = (relatedTo._phpIncludePathExpression as PhpConstValue).Value as string;
             if (pathRelTo == null)
             {
                 throw new NotSupportedException();
             }
         }
         if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(path))
         {
             var knownPath = ProcessPath(path, pathRelTo);
             return(new PhpConstValue(knownPath));
         }
         throw new NotSupportedException();
         //var aaaa = "/" + name + extension;
         //if (phpIncludePathExpression == null)
         //    return null;
         //if (phpIncludePathExpression is PhpConstValue)
         //{
         //    aaaa = ((phpIncludePathExpression as PhpConstValue).Value ?? "").ToString() + aaaa;
         //    return ProcessPath(aaaa, relatedTo.emitPath);
         //    // return new PhpConstValue(aaaa, true);
         //}
         //var a = new PhpConstValue(aaaa, true);
         //var g = new PhpBinaryOperatorExpression(".", phpIncludePathExpression, a);
         //return g;
     }
     throw new NotSupportedException();
 }
Exemplo n.º 4
0
 public static IPhpValue MakePathValueRelatedToFile(string path)
 {
     path = MakeUnixPath(path + UNIX_SEP);
     if (!path.StartsWith(UNIX_SEP))
         path = UNIX_SEP + path;
     var _FILE_ = new PhpDefinedConstExpression("__FILE__", null);
     var dirinfo = new PhpMethodCallExpression("dirname", _FILE_);
     var a2 = new PhpConstValue(path);
     var concat = new PhpBinaryOperatorExpression(".", dirinfo, a2);
     return concat;
 }
 /// <summary>
 /// Helper method
 /// </summary>
 /// <param name="items"></param>
 /// <returns></returns>
 public static IPhpValue ConcatStrings(params IPhpValue[] items)
 {
     if (items == null) return null;
     IPhpValue result = null;
     foreach (var i in items)
     {
         if (result == null)
             result = i;
         else
             result = new PhpBinaryOperatorExpression(".", result, i);
     }
     if (result != null)
     {
         var simplifier = new ExpressionSimplifier(new OptimizeOptions());
         result = simplifier.Simplify(result);
     }
     return result;
 }
Exemplo n.º 6
0
        // Private Methods 

        private IPhpValue _JoinArray()
        {
            if (list.Count == 1)
                return list[0];
            var e = list[0];
            for (var i = 1; i < list.Count; i++)
            {
                var a = list[i];
                e = new PhpBinaryOperatorExpression(".", e, a);
            }
            return e;
        }