| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\ComException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Instructs COM to sink events generated by |
| 9 |
* comobject into the PHP object |
| 10 |
* sinkobject. |
| 11 |
* |
| 12 |
* Be careful how you use this feature; if you are doing something similar |
| 13 |
* to the example below, then it doesn't really make sense to run it in a |
| 14 |
* web server context. |
| 15 |
* |
| 16 |
* @param object $comobject |
| 17 |
* @param object $sinkobject sinkobject should be an instance of a class with |
| 18 |
* methods named after those of the desired dispinterface; you may use |
| 19 |
* com_print_typeinfo to help generate a template class |
| 20 |
* for this purpose. |
| 21 |
* @param mixed $sinkinterface PHP will attempt to use the default dispinterface type specified by |
| 22 |
* the typelibrary associated with comobject, but |
| 23 |
* you may override this choice by setting |
| 24 |
* sinkinterface to the name of the dispinterface |
| 25 |
* that you want to use. |
| 26 |
* @throws ComException |
| 27 |
* |
| 28 |
*/ |
| 29 |
function com_event_sink(object $comobject, object $sinkobject, $sinkinterface = null): void |
| 30 |
{ |
| 31 |
error_clear_last(); |
| 32 |
if ($sinkinterface !== null) { |
| 33 |
$result = \com_event_sink($comobject, $sinkobject, $sinkinterface); |
| 34 |
} else { |
| 35 |
$result = \com_event_sink($comobject, $sinkobject); |
| 36 |
} |
| 37 |
if ($result === false) { |
| 38 |
throw ComException::createFromPhpError(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Loads a type-library and registers its constants in the engine, as though |
| 45 |
* they were defined using define. |
| 46 |
* |
| 47 |
* Note that it is much more efficient to use the configuration setting to pre-load and |
| 48 |
* register the constants, although not so flexible. |
| 49 |
* |
| 50 |
* If you have turned on , then |
| 51 |
* PHP will attempt to automatically register the constants associated with a |
| 52 |
* COM object when you instantiate it. This depends on the interfaces |
| 53 |
* provided by the COM object itself, and may not always be possible. |
| 54 |
* |
| 55 |
* @param string $typelib_name typelib_name can be one of the following: |
| 56 |
* |
| 57 |
* |
| 58 |
* |
| 59 |
* The filename of a .tlb file or the executable module |
| 60 |
* that contains the type library. |
| 61 |
* |
| 62 |
* |
| 63 |
* |
| 64 |
* |
| 65 |
* The type library GUID, followed by its version number, for example |
| 66 |
* {00000200-0000-0010-8000-00AA006D2EA4},2,0. |
| 67 |
* |
| 68 |
* |
| 69 |
* |
| 70 |
* |
| 71 |
* The type library name, e.g. Microsoft OLE DB ActiveX Data |
| 72 |
* Objects 1.0 Library. |
| 73 |
* |
| 74 |
* |
| 75 |
* |
| 76 |
* PHP will attempt to resolve the type library in this order, as the |
| 77 |
* process gets more and more expensive as you progress down the list; |
| 78 |
* searching for the type library by name is handled by physically |
| 79 |
* enumerating the registry until we find a match. |
| 80 |
* |
| 81 |
* The filename of a .tlb file or the executable module |
| 82 |
* that contains the type library. |
| 83 |
* |
| 84 |
* The type library GUID, followed by its version number, for example |
| 85 |
* {00000200-0000-0010-8000-00AA006D2EA4},2,0. |
| 86 |
* |
| 87 |
* The type library name, e.g. Microsoft OLE DB ActiveX Data |
| 88 |
* Objects 1.0 Library. |
| 89 |
* @param bool $case_sensitive The case_sensitive behaves inversely to |
| 90 |
* the parameter $case_insensitive in the define |
| 91 |
* function. |
| 92 |
* @throws ComException |
| 93 |
* |
| 94 |
*/ |
| 95 |
function com_load_typelib(string $typelib_name, bool $case_sensitive = true): void |
| 96 |
{ |
| 97 |
error_clear_last(); |
| 98 |
$result = \com_load_typelib($typelib_name, $case_sensitive); |
| 99 |
if ($result === false) { |
| 100 |
throw ComException::createFromPhpError(); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/** |
| 106 |
* The purpose of this function is to help generate a skeleton class for use |
| 107 |
* as an event sink. You may also use it to generate a dump of any COM |
| 108 |
* object, provided that it supports enough of the introspection interfaces, |
| 109 |
* and that you know the name of the interface you want to display. |
| 110 |
* |
| 111 |
* @param object $comobject comobject should be either an instance of a COM |
| 112 |
* object, or be the name of a typelibrary (which will be resolved according |
| 113 |
* to the rules set out in com_load_typelib). |
| 114 |
* @param string $dispinterface The name of an IDispatch descendant interface that you want to display. |
| 115 |
* @param bool $wantsink If set to TRUE, the corresponding sink interface will be displayed |
| 116 |
* instead. |
| 117 |
* @throws ComException |
| 118 |
* |
| 119 |
*/ |
| 120 |
function com_print_typeinfo(object $comobject, string $dispinterface = null, bool $wantsink = false): void |
| 121 |
{ |
| 122 |
error_clear_last(); |
| 123 |
$result = \com_print_typeinfo($comobject, $dispinterface, $wantsink); |
| 124 |
if ($result === false) { |
| 125 |
throw ComException::createFromPhpError(); |
| 126 |
} |
| 127 |
} |
| 128 |
|