本文整理匯總了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;
}