本文整理汇总了PHP中str::studly方法的典型用法代码示例。如果您正苦于以下问题:PHP str::studly方法的具体用法?PHP str::studly怎么用?PHP str::studly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::studly方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
/**
* Display the specified Element.
* GET|HEAD /elements/{id}
*
* @param Request $request
* @param int $id
*
* @return Response
*/
public function show(Request $request, $id)
{
$element = $this->elementRepository->apiFindOrFail($id);
$response = $this->response();
//todo: move this to middleware in order to handle content negotiation
$format = Str::lower($request->get('format', 'json'));
$item = $response->item($element, new ElementTransformer());
$resource = new Item($element, new ElementTransformer());
$properties = [];
//make sure we're sending utf-8
//sendResponse always sends json
if ('json' == $format) {
foreach ($element->ElementProperties as $elementProperty) {
if ($elementProperty->profileProperty->has_language) {
$properties[$elementProperty->language][$elementProperty->ProfileProperty->name] = $elementProperty->object;
} else {
$properties[$elementProperty->ProfileProperty->name] = $elementProperty->object;
}
}
$result = ['uri' => $element->uri, 'properties' => $properties];
return $this->sendResponse($result, "Element retrieved successfully");
} else {
//todo: move this to a formatter
foreach ($element->ElementProperties as $elementProperty) {
$properties[$elementProperty->ProfileProperty->name . '.' . $elementProperty->language] = $elementProperty;
}
ksort($properties, SORT_NATURAL | SORT_FLAG_CASE);
//build the xml
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><response/>');
$xml->registerXPathNamespace('xml', 'http://www.w3.org/XML/1998/namespace');
$data = $xml->addChild('data');
$data->addAttribute('uri', $element->uri);
$status = $data->addChild('status', $element->Status->display_name);
$status->addAttribute('uri', $element->Status->uri);
foreach ($properties as $elementProperty) {
$key = $elementProperty->ProfileProperty->name;
if (in_array($key, ['statusId', 'uri'])) {
continue;
}
if ($elementProperty->profileProperty->has_language) {
$property = $data->addChild($key, $elementProperty->object);
$property->addAttribute('xml:lang', $elementProperty->language, 'xml');
} else {
try {
$relatedElement = $this->elementRepository->apiFindOrFail($elementProperty->related_schema_property_id);
} catch (HttpException $e) {
}
$relatedProperties = [];
foreach ($relatedElement->ElementProperties as $relElementProperty) {
$relatedProperties[$relElementProperty->ProfileProperty->name . '.' . $relElementProperty->language] = $relElementProperty;
}
//todo: set the label language based on language request
$relKey = array_key_exists('label.en', $relatedProperties) ? 'label.en' : 'label.';
//todo: Fix this hack
if ('type' == $key) {
$property = $data->addChild($key, str::studly($elementProperty->object));
continue;
}
$property = $data->addChild($key, $relatedProperties[$relKey]->object);
$property->addAttribute('uri', $elementProperty->object);
}
}
$message = $xml->addChild('message', "Element retrieved successfully");
return Response::make($xml->asXML(), 200)->header('Content-Type', 'application/xml');
}
}