| 1 | /**
|
|---|
| 2 | * Modified VBox_ManagedObjectCollection constructor
|
|---|
| 3 | */
|
|---|
| 4 | public function __construct($soap, array $handles = array())
|
|---|
| 5 | {
|
|---|
| 6 | $this->connection = $soap;
|
|---|
| 7 | $this->handles = $handles;
|
|---|
| 8 |
|
|---|
| 9 | /**
|
|---|
| 10 | * Start of modifications
|
|---|
| 11 | *
|
|---|
| 12 | * Description: Each collection is an array of VirtualBox objects
|
|---|
| 13 | * (ex: list of machines). The problem here occurs when there is
|
|---|
| 14 | * only one object present (ex: one shared folder). In this
|
|---|
| 15 | * situation an array with one elemnt is expected but the
|
|---|
| 16 | * element itself is returned. This workaround attempts to
|
|---|
| 17 | * fix this by properly creating the expected one elemnt array.
|
|---|
| 18 | *
|
|---|
| 19 | * Note: This workaround relies on these two assumptions:
|
|---|
| 20 | * - a valid collection always contains only objects
|
|---|
| 21 | * - an invalid collection has some non object elements
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * Checks if a "faulty" interface is being constructed
|
|---|
| 26 | *
|
|---|
| 27 | * Note: So far only the IMediumAttachment and ISharedFolder interfaces
|
|---|
| 28 | * seem to be having trouble with collections. Allowing this "fix"
|
|---|
| 29 | * to tamper with all other interfaces will break them.
|
|---|
| 30 | */
|
|---|
| 31 | if($this->_interfaceName != "IMediumAttachment" && $this->_interfaceName != "ISharedFolder")
|
|---|
| 32 | return;
|
|---|
| 33 | else
|
|---|
| 34 | ;
|
|---|
| 35 |
|
|---|
| 36 | /**
|
|---|
| 37 | * Checks if each element of the collection is an object and does the
|
|---|
| 38 | * appropriate modification if an invalid elemnt is found
|
|---|
| 39 | */
|
|---|
| 40 | foreach($this->handles as $value)
|
|---|
| 41 | {
|
|---|
| 42 | if(!is_object($value))
|
|---|
| 43 | {
|
|---|
| 44 | //an invalid element is found and it needs to be properly wrapped
|
|---|
| 45 | //inside an object, becoming the only elemnt in the $this->handles array
|
|---|
| 46 | $this->handles = array(0 => (object)$this->handles);
|
|---|
| 47 | break;
|
|---|
| 48 | }
|
|---|
| 49 | else
|
|---|
| 50 | ;
|
|---|
| 51 | }
|
|---|
| 52 | /**
|
|---|
| 53 | * End of modifications
|
|---|
| 54 | */
|
|---|
| 55 | }
|
|---|