- Timestamp:
- Apr 26, 2010 6:44:11 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/webservice/websrv-php.xsl
r27646 r28775 270 270 </xsl:template> 271 271 272 <xsl:template name="structcollection"> 273 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable> 274 <xsl:text> 275 /** 276 * Generated VBoxWebService Struct Collection 277 */</xsl:text> 278 class <xsl:value-of select="$ifname"/>Collection extends VBox_StructCollection { 279 protected $_interfaceName = "<xsl:value-of select="$ifname"/>"; 280 } 281 </xsl:template> 282 272 283 <xsl:template name="genreq"> 273 284 <xsl:param name="wsmap" /> … … 334 345 </xsl:template> 335 346 347 <xsl:template name="enumcollection"> 348 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable> 349 <xsl:text> 350 /** 351 * Generated VBoxWebService Enum Collection 352 */</xsl:text> 353 class <xsl:value-of select="$ifname"/>Collection extends VBox_EnumCollection { 354 protected $_interfaceName = "<xsl:value-of select="$ifname"/>"; 355 } 356 </xsl:template> 357 336 358 <xsl:template match="/"> 337 359 <xsl:text><?php … … 360 382 protected $handle; 361 383 362 public function 384 public function __construct($soap, $handle = null) 363 385 { 364 386 $this->connection = $soap; … … 414 436 } 415 437 416 class VBox_ManagedObjectCollection implements Iterator, Countable { 417 protected $connection; 418 protected $handles; 419 protected $_interfaceName = null; 420 421 public function __construct($soap, array $handles = array()) 422 { 423 $this->connection = $soap; 424 $this->handles = $handles; 425 } 426 438 abstract class VBox_Collection implements ArrayAccess, Iterator, Countable { 439 protected $_connection; 440 protected $_values; 441 protected $_objects; 442 protected $_interfaceName; 443 444 public function __construct($soap, array $values = array()) { 445 $this->_connection = $soap; 446 $this->_values = $values; 447 $this->_soapToObject(); 448 } 449 450 protected function _soapToObject() { 451 $this->_objects = array(); 452 foreach($this->_values as $value) 453 { 454 $this->_objects[] = new $this->_interfaceName($this->_connection, $value); 455 } 456 } 457 458 /** ArrayAccess Functions **/ 459 public function offsetSet($offset, $value) { 460 if ($value instanceof $this->_interfaceName) 461 { 462 if ($offset) 463 { 464 $this->_objects[$offset] = $value; 465 } 466 else 467 { 468 $this->_objects[] = $value; 469 } 470 } 471 else 472 { 473 throw new Exception("Value must be a instance of " . $this->_interfaceName); 474 } 475 } 476 477 public function offsetExists($offset) { 478 return isset($this->_objects[$offset]); 479 } 480 481 public function offsetUnset($offset) { 482 unset($this->_objects[$offset]); 483 } 484 485 public function offsetGet($offset) { 486 return isset($this->_objects[$offset]) ? $this->_objects[$offset] : null; 487 } 488 489 /** Iterator Functions **/ 427 490 public function rewind() { 428 reset($this-> handles);491 reset($this->_objects); 429 492 } 430 493 431 494 public function current() { 432 $handle = current($this->handles); 433 if ($handle !== false && !$handle instanceof $this->_interfaceName) { 434 $handle = new $this->_interfaceName($this->connection, $handle); 435 } 436 return $handle; 495 return current($this->_objects); 437 496 } 438 497 439 498 public function key() { 440 $handle = key($this->handles); 441 return $handle; 499 return key($this->_objects); 442 500 } 443 501 444 502 public function next() { 445 $handle = next($this->handles); 446 return $handle; 503 return next($this->_objects); 447 504 } 448 505 449 506 public function valid() { 450 $handle = $this->current() !== false;451 return $handle;452 } 453 507 return ($this->current() !== false); 508 } 509 510 /** Countable Functions **/ 454 511 public function count() { 455 return count($this->handles); 512 return count($this->_objects); 513 } 514 } 515 516 class VBox_ManagedObjectCollection extends VBox_Collection { 517 protected $_interfaceName = 'VBox_ManagedObject'; 518 519 // Result is undefined if this is called AFTER any call to VBox_Collection::offsetSet or VBox_Collection::offsetUnset 520 public function setInterfaceName($interface) { 521 if (!is_subclass_of($interface, 'VBox_ManagedObject')) 522 { 523 throw new Exception('Cannot set collection interface to non-child class of VBox_ManagedObject'); 524 } 525 $this->_interfaceName = $interface; 526 $this->_soapToObject(); 456 527 } 457 528 } … … 470 541 } 471 542 543 abstract class VBox_StructCollection extends VBox_Collection { 544 545 public function __construct($soap, array $values = array()) 546 { 547 if (!(array_values($values) === $values)) 548 { 549 $values = array((object)$values); //Fix for when struct return value only contains one list item (e.g. one medium attachment) 550 } 551 parent::__construct($soap, $values); 552 } 553 } 554 472 555 abstract class VBox_Enum { 473 protected $ handle;556 protected $_handle; 474 557 475 558 public function __construct($connection, $handle) 476 559 { 477 560 if (is_string($handle)) 478 $this-> handle = $this->ValueMap[$handle];561 $this->_handle = $this->ValueMap[$handle]; 479 562 else 480 $this-> handle = $handle;563 $this->_handle = $handle; 481 564 } 482 565 483 566 public function __toString() 484 567 { 485 return (string)$this->NameMap[$this->handle]; 486 } 568 return (string)$this->NameMap[$this->_handle]; 569 } 570 } 571 572 abstract class VBox_EnumCollection extends VBox_Collection { 487 573 } 488 574 … … 494 580 <xsl:for-each select="//interface[@wsmap='struct']"> 495 581 <xsl:call-template name="interfacestruct"/> 496 <xsl:call-template name=" collection"/>582 <xsl:call-template name="structcollection"/> 497 583 </xsl:for-each> 498 584 <xsl:for-each select="//enum"> 499 585 <xsl:call-template name="enum"/> 500 <xsl:call-template name=" collection"/>586 <xsl:call-template name="enumcollection"/> 501 587 </xsl:for-each> 502 588
Note:
See TracChangeset
for help on using the changeset viewer.