当前位置: 首页>>代码示例>>PHP>>正文


PHP Method::createFromArray方法代码示例

本文整理汇总了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;
 }
开发者ID:cnam,项目名称:php-raml-parser,代码行数:73,代码来源:Resource.php

示例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;
 }
开发者ID:cozylife,项目名称:php-raml-parser,代码行数:54,代码来源:Resource.php


注:本文中的Method::createFromArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。