コード例 #1
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();
 }
コード例 #2
0
ファイル: PathUtil.cs プロジェクト: exaphaser/cs2php
 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;
 }