本文整理汇总了PHP中Resource::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP Resource::getType方法的具体用法?PHP Resource::getType怎么用?PHP Resource::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resource
的用法示例。
在下文中一共展示了Resource::getType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serializeResource
public function serializeResource(Resource $resource)
{
$data['id'] = $resource->getId();
$data['_type'] = $resource->getType()->getName();
$data['href'] = $this->primate->getBaseUrl() . '/' . $resource->getType()->getName() . '/' . $resource->getId();
foreach ($resource->getProperties() as $name => $value) {
switch (gettype($value)) {
case 'array':
$data[$name] = '[]';
break;
case 'object':
if (is_subclass_of($value, '\\Primate\\ResourceInterface')) {
$data[$name] = $this->serializeResource($value);
} else {
$data[$name] = '???';
}
break;
default:
$data[$name] = $value;
break;
}
}
return $data;
}
示例2: loadResource
public function loadResource(Resource $resource, $expands = [])
{
$repo = $resource->getType()->getRepository();
$resources = [$resource];
$repo->loadResources($resources, $this);
foreach ($resource->getProperties() as $key => $value) {
if (in_array($key, $expands)) {
foreach ($expands as $expand) {
$subExpands = [];
if (substr($expand, 0, strlen($key) + 1) == $key . '.') {
$subExpands[] = substr($expand, strlen($key) + 1);
}
}
$subResource = $resource->getProperty($key);
$this->loadResource($subResource, $subExpands);
}
}
return $resource;
}
示例3: resolve
/**
* Returns the loader for a resource.
*
* @param Resource $resource The resource.
*
* @return LoaderInterface|null The resource loader.
*/
public function resolve(Resource $resource)
{
if ($resource instanceof ResourceSupport) {
$loader = $this->resolver->resolve($resource->getSupportResource(), $resource->getSupportType());
} else {
$loader = $this->resolver->resolve($resource->getResource(), $resource->getType());
}
return false === $loader ? null : $loader;
}