示例#1
1
文件: dotnet.php 项目: OTiZ/osx
<?
  $stack = new DOTNET("mscorlib","System.Collections.Stack");

  $stack->Push(".Net");
  $stack->Push("Hello ");

  echo $stack->Pop() . $stack->Pop();
?>
 public static function run($dataDir = null)
 {
     if (is_null($dataDir)) {
         die("Data Directory Undefined");
     }
     // Create Aspose.Cells Helper Object
     $ptr = new \COM('Aspose.Cells.Interop.InteropHelper');
     // Opening through Path
     // Creating a Workbook object and opening an Excel file using its file path
     $workbook = $ptr->New("Aspose.Cells.Workbook", array($dataDir . '/MyTestBook1.xls'));
     $worksheets = $ptr->Get($workbook, "Worksheets", array());
     $sheet = $ptr->Get($worksheets, 'Item', array(0));
     $imgOptions = $ptr->New("Aspose.Cells.Rendering.ImageOrPrintOptions", array());
     $imageFormat = new \DOTNET('mscorlib', 'System.Drawing.Imaging.ImageFormat');
     $ptr->Set($imgOptions, 'ImageFormat', $imageFormat->Jpeg, array());
     $ptr->Set($imgOptions, 'OnePagePerSheet', true, array());
     $sr = $ptr->New("Aspose.Cells.Rendering.SheetRender", array($sheet, $imgOptions));
     $bitmap = new \DOTNET("mscorlib", "System.Drawing.Bitmap");
     $bitmap->Save($dataDir . "./SheetImage.jpg");
     print "Conversion to Image(s) completed!" . PHP_EOL;
 }
 /**
  * This method will generate strong random data for cryptographic use.
  *
  * @param int $length
  * @return binary
  */
 public static function getRandomBytes($length)
 {
     $length = (int) $length;
     if ($length < 1) {
         throw new Exception('Length cannot be less than 1.');
     }
     // Works on systems that have OpenSSL installed and OpenSSL extension loaded.
     if (function_exists('openssl_random_pseudo_bytes')) {
         $random = openssl_random_pseudo_bytes($length, $strong);
         if ($strong) {
             return (string) $random;
         }
     }
     // Only execute on unix based systems
     if (DIRECTORY_SEPARATOR === '/') {
         // Works on Sun Solaris, Unix and Linux systems.
         $fp = @fopen('/dev/urandom', 'rb');
         if ($fp) {
             $random = fread($fp, $length);
             fclose($fp);
             return (string) $random;
         }
     }
     // Works on Windows x86.
     if (class_exists('COM')) {
         try {
             $csp = new COM('CAPICOM.Utilities.1');
             // We are stripping because sometimes the method appends newlines?
             $random = substr((string) base64_decode($csp->getrandom($length, 0)), 0, $length);
             unset($csp);
             return (string) $random;
         } catch (Exception $e) {
         }
     }
     // PHP has a bug that prevents you from creating a byte array via variants. Thus, no CSP support for Windows x64.
     // If someone is able to circumvent this problem, please email me.
     // Could work on Windows x64.
     if (false) {
         if (class_exists('DOTNET')) {
             try {
                 $csp = new DOTNET("mscorlib", "System.Security.Cryptography.RNGCryptoServiceProvider");
                 $array = array_fill(0, $length, null);
                 $variant = new VARIANT($array, VT_ARRAY | VT_UI1);
                 $csp->GetBytes($variant);
                 unset($csp);
                 return (string) implode('', $array);
             } catch (Exception $e) {
             }
         }
     }
     // This is random data from OpenSSL that was marked as "weak". It's better than mt_rand().
     if (isset($random)) {
         return (string) $random;
     }
     // Falling back to PHP's mt_rand() and the rest if nothing worked.
     // This basically means we are either on a Windows x64 system without OpenSSL or on a really weird system. :|
     $random = '';
     $backtrace = debug_backtrace();
     $stat = stat($backtrace[0]['file']);
     // Using the name of the caller script.
     for ($a = 0; $a < $length; $a++) {
         // Since we can't use any good random generators, we need to use as many poor "random" sources as possible.
         $source = mt_rand();
         // Weak pseudo random.
         $source += microtime(true);
         // Non-random and is poor in tight loops - yes, like this one.
         // $source += uniqid('', true); // The only real reason to use uniqid() here is due to its use of the internal LCG.
         $source += memory_get_usage();
         // Has a weak avalance effect and is predictable.
         $source += getmypid();
         // Non-random and doesn't change until the next request.
         $source += $stat[7] + substr($stat[8], -3, 3) + substr($stat[9], -3, 3) + substr($stat[10], -3, 3);
         // File stats.
         // Let's make it a byte.
         $random .= chr($source % 255);
     }
     return (string) $random;
 }