note 118286 added to class.com

From: Date: Sun, 08 Nov 2015 15:22:28 +0000
Subject: note 118286 added to class.com
Groups: php.notes 
Request: Send a blank email to php-notes+get-204113@lists.php.net to get a copy of this message
This is an example of using .Net using the NetPhp library that is based on the COM/DOTNET classes. You can use any .dll file, wether it is or not COM decorated and any of the .Net framework types out of the box. You can also target any version of the .Net framework. <?php $runtime = new \NetPhp\Core\NetPhpRuntime('COM', 'netutilities.NetPhpRuntime'); // Add both SpreadsheetLight and the OpenXML it depends on. $runtime->RegisterAssemblyFromFile('/binaries/SpreadsheetLight.dll', 'SpreadsheetLight'); $runtime->RegisterAssemblyFromFile('/binaries/DocumentFormat.OpenXml.dll', 'DocumentFormat.OpenXml'); $runtime->RegisterAssemblyFromFile('/binaries/AjaxMin.dll', 'AjaxMin'); // Using the FullName of a type that belongs to an assembly that has already been registered. $datetime = $runtime->TypeFromName("System.DateTime"); // Using the FullName of a type that has not been registered yet (from a file) $minifier = $runtime->TypeFromFile("Microsoft.Ajax.Utilities.Minifier", APPLICATION_ROOT . '/binaries/AjaxMin.dll'); // Using the FullName of a type that has not been registered yet (autodiscoverable) $datetime2 = $runtime->TypeFromAssembly("System.DateTime", "mscorlib, ...."); $datetime->Instantiate(); echo $datetime->ToShortDateString()->Val(); // Outputs 01/01/0001 // We can only use Int32 from native PHP, so parse // an Int64 that is equivalent to (long) in the DateTime constructor. $ticks = $runtime->TypeFromName("System.Int64")->Parse('98566569856565656'); $datetime->Instantiate($ticks); echo $datetime->ToShortDateString()->Val(); // Outputs 07/05/0313 // We can only use Int32 from native PHP, so parse // an Int64 that is equivalent to (long) in the DateTime constructor. $ticks = $runtime->TypeFromName("System.Int64")->Parse('98566569856565656'); // Dump a .Net System.Timers.Timer object! $data = $timer->GetPhpFromJson(); var_dump($data); // Outputs: // object(stdClass)[38] // public 'AutoReset' => boolean true // public 'Enabled' => boolean false // public 'Interval' => int 100 // public 'Site' => null // public 'SynchronizingObject' => null // public 'Container' => null // Check if today is monday $IsMonday = $runtime->TypeFromName("System.DateTime")->Now->DayOfWeek-> Equals($runtime->TypeFromName("System.DayOfWeek")->Enum('Monday')); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 177.242.42.214 ---- Manual Page -- http://php.net/manual/en/class.com.php Edit -- https://master.php.net/note/edit/118286 Del: integrated -- https://master.php.net/note/delete/118286/integrated Del: useless -- https://master.php.net/note/delete/118286/useless Del: bad code -- https://master.php.net/note/delete/118286/bad+code Del: spam -- https://master.php.net/note/delete/118286/spam Del: non-english -- https://master.php.net/note/delete/118286/non-english Del: in docs -- https://master.php.net/note/delete/118286/in+docs Del: other reasons-- https://master.php.net/note/delete/118286 Reject -- https://master.php.net/note/reject/118286 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204113) next »