Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Introduce 1.3.0 templates for PHP #41

Merged
merged 3 commits into from Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/googleapis/codegen/languages/php/1.3.0/features.json
@@ -0,0 +1,14 @@
{
"language": "php",
"description": "PHP libraries for Google APIs.",
"releaseVersion": "1.3.0",
"baseClientLibrary": "1.1.1",
"requires": [
{
"name": "Google API PHP Client",
"environments": ["*"],
"downloadLink": "https://github.com/google/google-api-php-client/releases",
"version": "${baseClientLibrary}"
}
]
}
@@ -0,0 +1,70 @@
<?php
{% language php %}{% copyright_block %}

/**
* Service definition for {{ api.className }} ({{ api.version }}).
*
* <p>{% filter block_comment %}
* {{ api.description }}
* {% endfilter %}</p>
*
* <p>
* For more information about this service, see the API
* <a href="{{ api.documentationLink }}" target="_blank">Documentation</a>
* </p>
*
* @author Google, Inc.
*/
class {{ api.ownerName }}_Service_{{ api.className }} extends Google_Service
{
{% if api.auth.oauth2.scopes %}{% filter noblanklines %}{% indent %}
{% for authscope in api.authscopes %}
/** {{ authscope.description }}. */
const {{ authscope.name }} =
"{{ authscope.value }}";
{% endfor %}{% endindent %}{% endfilter %}{% endif %}

{% call_template _resource_var resource=api %}
{% if api.methods %}private $base_methods;{% endif %}
/**{% filter block_comment %}
* Constructs the internal representation of the {{ api.className }} service.
* {% endfilter %}
*
* @param Google_Client $client The client used to deliver requests.
* @param string $rootUrl The root URL used for requests to the service.
*/
public function __construct(Google_Client $client, $rootUrl = null)
{
{% filter noblanklines %}
{% indent 2 %}
parent::__construct($client);
$this->rootUrl = $rootUrl ?: {% literal api.rootUrl %};
$this->servicePath = {% literal api.servicePath %};
{% if api.batchPath %}$this->batchPath = {% literal api.batchPath %};{% endif %}
$this->version = {% literal api.version %};
$this->serviceName = {% literal api.name %};
{% endindent %}
{% endfilter %}

{% filter noblanklines %}
{% call_template _resource_decl resource=api %}
{% indent %}
{% indent %}
{% if api.methods %}
$this->base_methods = new Google_Service_Resource(
$this,
$this->serviceName,
'{{ resource.codeName }}',
{% indent 2 %}{% call_template _methods_decl methods=api.methods %}{% endindent %}
);
{% endif %}
{% endindent %}
{% endindent %}
}
{% indent %}
{% for m in api.methods %}
{% call_template _method baseMethod=1 method=m %}
{% endfor %}
{% endindent %}
{% endfilter %}
}
@@ -0,0 +1,15 @@
<?php
{% language php %}{% copyright_block %}

/**
* The "{{ resource.wireName }}" collection of methods.
* Typical usage is:
* <code>
* ${{ api.name }}Service = new {{ api.ownerName }}_Service_{{ api.className }}(...);
* ${{ resource.codeName }} = ${{ api.name }}Service->{{ resource.codeName }};
* </code>
*/
class {{ api.ownerName }}_Service_{{ api.className }}_Resource_{{ resource.className }} extends Google_Service_Resource
{{% indent %}{% for method in resource.methods %}
{% call_template _method method=method %}{% endfor %}
{% endindent %}}
@@ -0,0 +1,62 @@
<?php
{% language php %}{% copyright_block %}

class {{ api.ownerName }}_Service_{{ api.className }}_{{ model.className }} {% if model.superClass %}extends {{ api.ownerName }}_Service_{{ api.className }}_{{ model.superClass }}{% else %}{% if model.dataType == "array" %}extends Google_Collection{% else %}extends Google_Model{% endif %}{% endif %}
{{% if model.properties %}
{% filter noblanklines %}
{% if not model.is_variant_base and model.collectionKey %}
protected $collection_key = '{{ model.collectionKey }}';
{% endif %}{% if model.has_gapi %}
protected $internal_gapi_mappings = array(
{% for property in model.properties %}
{% if not property.member_name_is_json_name %}
"{{ property.memberName }}" => "{{ property.wireName }}",
{% endif %}
{% endfor %}
);
{% endif %}{% for property in model.properties %}
{% if property.typeHint %}
{% if property.memberName|add:"Type" not in model.propNames %}
protected ${{ property.memberName }}Type = '{{ property.typeHint|cut:" " }}';
{% endif %}{% if property.memberName|add:"DataType" not in model.propNames %}
protected ${{ property.memberName }}DataType = '{{ property.dataType }}';
{% endif %}
{% else %}
public ${{ property.memberName }};
{% endif %}
{% endfor %}
{% endfilter %}
{% filter noblanklines %}
{% if model.discriminantValue %}
protected function gapiInit()
{
$this->type = {% literal model.discriminantValue %};
}
{% endif %}
{% endfilter %}{% for property in model.properties %}
{% filter noblanklines %}
{% if property.typeHint %}
/**
* @param {{ property.typeHint }}
*/
{% endif %}
{% if property.type == "array" or property.dataType == "map" or not property.typeHint %}
public function {{ property.setterName }}(${{ property.memberName }})
{% else %}
public function {{ property.setterName }}({{ property.typeHint }} ${{ property.memberName }})
{% endif %}
{
$this->{{ property.memberName }} = ${{ property.memberName }};
}

{% if property.typeHint %}
/**
* @return {{ property.typeHint }}
*/
{% endif %}
public function {{ property.getterName }}()
{
return $this->{{ property.memberName }};
}
{% endfilter %}{% endfor %}{% endif %}
}
@@ -0,0 +1,11 @@
{% parameter_list %}
{% for p in method.requiredParameters %}
{% parameter %}{{ p.typeHint }} ${{p.memberName}}{% end_parameter %}
{% endfor %}
{% if method.requestType %}
{% parameter %}
{{ api.ownerName }}_Service_{{ api.className }}_{{ method.requestType.className }} $postBody
{% end_parameter %}
{% endif %}
{% parameter %}$optParams = array(){% end_parameter %}
{% end_parameter_list %}
41 changes: 41 additions & 0 deletions src/googleapis/codegen/languages/php/1.3.0/templates/_method.tmpl
@@ -0,0 +1,41 @@
/**{% filter block_comment %}
* {{ method.description }} ({% if resource %}{{ resource.wireName }}.{% endif %}{{ method.name }})
* {% endfilter %}
*
{% filter noblanklines %}
{% for param in method.required_parameters %}{% filter block_comment %}
* @param {{ param.codeType }}{% if param.repeated %}|array{% endif %} ${{ param.memberName }}
* {{ param.description }}{% endfilter %}{% endfor %}
{% if method.requestType %}
* @param {{ api.ownerName }}_Service_{{ api.className }}_{{ method.requestType.className }} $postBody
{% endif %}
* @param array $optParams Optional parameters.
{% if method.optional_parameters %}
*{% for param in method.optional_parameters %}{% filter block_comment %}
* @opt_param {{ param.codeType }} {{ param.wireName }}
* {{ param.description }}{% endfilter %}{% endfor %}
{% endif %}
{% if method.response %}
* @return {{ api.ownerName }}_Service_{{ api.className }}_{{ method.responseType.className }}
{% endif %}
*/
{% endfilter %}
public function {{ method.name }}({% call_template _func_params method=method %})
{
{% filter noblanklines %}
$params = array({% parameter_list %}
{% for p in method.requiredParameters %}
{% parameter %}'{{ p.wireName }}' => ${{ p.memberName }}{% end_parameter %}
{% endfor %}
{% if method.requestType %}
{% parameter %}'postBody' => $postBody{% end_parameter %}
{% endif %}
{% end_parameter_list %});
$params = array_merge($params, $optParams);
{% if method.response %}
return $this->{% if baseMethod == 1 %}base_methods->{% endif %}call('{{ method.wireName }}', array($params), "{{ api.ownerName }}_Service_{{ api.className }}_{{ method.responseType.className }}");
{% else %}
return $this->{% if baseMethod == 1 %}base_methods->{% endif %}call('{{ method.wireName }}', array($params));
{% endif %}
{% endfilter %}
}
@@ -0,0 +1,16 @@
array(
'methods' => array(
{% for method in methods %}{% literal method.wireName %} => array(
'path' => {% literal method.path %},
'httpMethod' => {% literal method.httpMethod %},
'parameters' => array({% for p in method.parameters %}
{% literal p.wireName %} => array(
'location' => {% literal p.location %},
'type' => {% literal p.type %},
{% if p.repeated %}'repeated' => true,{% endif %}
{% if p.required %}'required' => true,{% endif %}
),
{% endfor %}),
),{% endfor %}
)
)
@@ -0,0 +1,14 @@
{% filter noblanklines %}
{% if resource.json %}
$this->{{ resource.phpPropName }} = new {{ api.ownerName }}_Service_{{ api.className }}_Resource_{{ resource.className }}(
$this,
$this->serviceName,
'{{ resource.codeName }}',
{% indent 4 %}{% call_template _methods_decl methods=resource.methods %}{% endindent %}
);
{% endif %}

{% for r in resource.resources %}
{% call_template _resource_decl resource=r %}
{% endfor %}
{% endfilter %}
@@ -0,0 +1,10 @@
{% filter noblanklines %}

{% if resource.json and resource.phpPropName %}
public ${{ resource.phpPropName }};
{% endif %}

{% for r in resource.resources %}
{% call_template _resource_var resource=r %}
{% endfor %}
{% endfilter %}