本文整理汇总了PHP中Method::createFromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Method::createFromArray方法的具体用法?PHP Method::createFromArray怎么用?PHP Method::createFromArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Method
的用法示例。
在下文中一共展示了Method::createFromArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFromArray
/**
* Create a Resource from an array
*
* @param string $uri
* @param array $data
* [
* uri: string
* displayName: ?string
* description: ?string
* baseUriParameters: ?array
* ]
*
* @param ApiDefinition $apiDefinition
* @param Resource $parentResource
*
* @return Resource
*/
public static function createFromArray($uri, array $data = [], ApiDefinition $apiDefinition = null, Resource $parentResource = null)
{
$resource = new static($uri, $apiDefinition);
if (isset($data['displayName'])) {
$resource->setDisplayName($data['displayName']);
} else {
$resource->setDisplayName($uri);
}
if (isset($data['description'])) {
$resource->setDescription($data['description']);
}
if (isset($data['baseUriParameters'])) {
foreach ($data['baseUriParameters'] as $key => $baseUriParameter) {
$resource->addBaseUriParameter(NamedParameter::createFromArray($key, $baseUriParameter));
}
}
if (isset($data['uriParameters'])) {
foreach ($data['uriParameters'] as $key => $uriParameter) {
$resource->addUriParameter(NamedParameter::createFromArray($key, $uriParameter ?: []));
}
}
if (null !== $parentResource) {
foreach ($parentResource->getUriParameters() as $uriParameter) {
$resource->addUriParameter($uriParameter);
}
}
if (isset($data['securedBy'])) {
foreach ($data['securedBy'] as $key => $securedBy) {
if (null !== $securedBy && $apiDefinition->getSecurityScheme($securedBy) instanceof SecurityScheme) {
$resource->addSecurityScheme($apiDefinition->getSecurityScheme($securedBy));
} else {
$resource->addSecurityScheme(SecurityScheme::createFromArray('null', array(), $apiDefinition));
}
}
}
foreach ($data as $key => $value) {
if (count($resource->getSecuritySchemes()) > 0) {
foreach ($resource->getSecuritySchemes() as $securityScheme) {
if ($securityScheme instanceof SecurityScheme && 'null' !== $securityScheme->getKey()) {
if (!isset($value['securedBy'])) {
if (!is_array($value)) {
$value = [];
}
$value['securedBy'][] = $securityScheme->getKey();
}
}
}
}
if (strpos($key, '/') === 0) {
$resource->addResource(Resource::createFromArray($uri . $key, $value ?: [], $apiDefinition, $resource));
} elseif (in_array(strtoupper($key), Method::$validMethods)) {
$resource->addMethod(Method::createFromArray($key, $value ?: [], $apiDefinition));
}
}
return $resource;
}
示例2: createFromArray
/**
* Create a Resource from an array
*
* @param string $uri
* @param ApiDefinition $apiDefinition
* @param array $data
* [
* uri: string
* displayName: ?string
* description: ?string
* baseUriParameters: ?array
* ]
*
* @return self
*/
public static function createFromArray($uri, array $data = [], ApiDefinition $apiDefinition = null)
{
$resource = new static($uri, $apiDefinition);
if (isset($data['displayName'])) {
$resource->setDisplayName($data['displayName']);
} else {
$resource->setDisplayName($uri);
}
if (isset($data['description'])) {
$resource->setDescription($data['description']);
}
if (isset($data['baseUriParameters'])) {
foreach ($data['baseUriParameters'] as $key => $baseUriParameter) {
$resource->addBaseUriParameter(BaseUriParameter::createFromArray($key, $baseUriParameter));
}
}
if (isset($data['uriParameters'])) {
foreach ($data['uriParameters'] as $key => $uriParameter) {
$resource->addUriParameter(NamedParameter::createFromArray($key, $uriParameter ?: []));
}
}
if (isset($data['securedBy'])) {
foreach ($data['securedBy'] as $securedBy) {
if ($securedBy) {
$resource->addSecurityScheme($apiDefinition->getSecurityScheme($securedBy));
} else {
$resource->addSecurityScheme(SecurityScheme::createFromArray('null', [], $apiDefinition));
}
}
}
foreach ($data as $key => $value) {
if (strpos($key, '/') === 0) {
$resource->addResource(Resource::createFromArray($uri . $key, $value ?: [], $apiDefinition));
} elseif (in_array(strtoupper($key), Method::$validMethods)) {
$resource->addMethod(Method::createFromArray($key, $value, $apiDefinition));
}
}
return $resource;
}