vCloud SDK for PHP Developer’s Guide
10
VMware, Inc.
Creating a Data Object
Each
data
object
class
includes
a
constructor
method
whose
parameters
represent
attributes
of
the
class
and
all
of
its
ancestors.
Attributes
are
marked
as
protected
to
restrict
their
visibility.
All
classes
contain
setter
and
getter
methods
for
XML
elements
and
attributes.
The
general
form
of
these
method
names
is
operation
_
attribute
‐
name
for
attributes
and
operation
ElementName
for
elements,
where
operation
is
one
of
set
or
get
.
For
example,
the
VMware_VCloud_API_ReferenceType
class
supports
set_name()
and
get_name()
methods
that
get
or
set
the
value
of
its
name
attribute,
and
the
VMware_VCloud_API_UserType
class
supports
setFullName()
and
getFullName()
methods
that
set
or
get
the
value
of
the
FullName
element
in
a
User
object.
To
create
a
data
object,
you
can
either
invoke
an
empty
constructor
and
then
call
the
setters
for
the
object
(see
Example 1
‐
1
),
or
invoke
the
constructor
with
parameters
(see
Example 1
‐
2
).
Example 1-1.
Create a Data Object From an Empty Constructor
$ref = new VMware_VCloud_API_ReferenceType();
$ref->set_href($href);
$ref->set_type($type);
$ref->set_name($name);
Example 1-2.
Create a Data Object With a Parameterized Constructor
$ref = new VMware_VCloud_API_ReferenceType ($href=$href, $type=$type, $name=$name);
Creating an SDK Object
You
can
create
an
SDK
object
when
you
need
to
invoke
a
lifecycle
operation
such
as
create
or
modify
on
a
vCloud
API
object.
Most
class
constructors
for
SDK
objects
require
two
parameters:
A
VMware_VCloud_SDK_Service
object,
which
contains
HTTP
connection
information.
A
ReferenceType
data
object
which
contains
the
request
URL.
For
more
information
about
request
URLs,
see
the
vCloud
API
Programming
Guide
.
For
example,
you
could
use
code
similar
to
the
fragment
shown
in
Example 1
‐
3
to
create
a
VMware_VCloud_SDK_Org
object
to
use
as
an
entrypoint
for
client
operations.
Example 1-3.
Creating an SDK Object
// get the list of all organizations in the vCloud
$orgRefs = $service->getOrgRefs($orgName);
// create an object that represents the first organization in the list
$sdkOrg = $service->createSDKObj($orgRefs[0]);
Table 1
‐
3
summarizes
the
types
of
SDK
objects
you
can
create
and
provides
information
to
help
you
choose
the
creation
parameters
(the
container
for
the
object,
and
a
method
to
use).
The
table
omits
the
VMware_VCloud_SDK_
part
of
the
package
names
in
the
SDK
Object
and
Container
Object
columns.
To use the information in the table to create an SDK object
1
Retrieve
an
array
of
object
references
by
specifying
a
container
object
and
a
creation
method.
$
references
=
Column2
->
Column3
2
For
any
reference
in
the
array,
create
an
SDK
object
using
the
selected
reference.
Column1
=$service->createSDKObj($
reference
)
Example 1
‐
3
applies
this
formula
to
creating
an
Org
object.