1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace POData\Providers\Stream; |
4
|
|
|
|
5
|
|
|
use POData\OperationContext\IOperationContext; |
6
|
|
|
use POData\Providers\Metadata\ResourceStreamInfo; |
7
|
|
|
use POData\Providers\Metadata\ResourceType; |
8
|
|
|
|
9
|
|
|
class SimpleStreamProvider implements IStreamProvider2 |
10
|
|
|
{ |
11
|
|
View Code Duplication |
public function getReadStream2($entity, ResourceStreamInfo $resourceStreamInfo = null, $eTag, $checkETagForEquality, IOperationContext $operationContext) |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
if (null == $resourceStreamInfo) { |
14
|
|
|
return "stream for " . get_class($entity); |
15
|
|
|
} |
16
|
|
|
$name = $resourceStreamInfo->getName(); |
17
|
|
|
return $entity->$name; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
View Code Duplication |
public function getDefaultStreamEditMediaUri($entity, ResourceType $resourceType, ResourceStreamInfo $resourceStreamInfo = null, IOperationContext $operationContext, $relativeUri = null) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
if (null == $resourceStreamInfo) { |
23
|
|
|
return $relativeUri . '/$value'; |
24
|
|
|
} |
25
|
|
|
return $relativeUri . '/' . $resourceStreamInfo->getName(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getStreamContentType2($entity, ResourceStreamInfo $resourceStreamInfo = null, IOperationContext $operationContext) |
29
|
|
|
{ |
30
|
|
|
if (null == $resourceStreamInfo) { |
31
|
|
|
return "*/*"; |
32
|
|
|
} |
33
|
|
|
return 'application/octet-stream'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function getStreamETag2( |
|
|
|
|
37
|
|
|
$entity, |
38
|
|
|
ResourceStreamInfo $resourceStreamInfo = null, |
39
|
|
|
IOperationContext $operationContext |
40
|
|
|
) { |
41
|
|
|
if (null == $resourceStreamInfo) { |
42
|
|
|
return spl_object_hash($entity); |
43
|
|
|
} |
44
|
|
|
$name = $resourceStreamInfo->getName(); |
45
|
|
|
|
46
|
|
|
return sha1($entity->$name); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function getReadStreamUri2( |
|
|
|
|
50
|
|
|
$entity, |
51
|
|
|
ResourceStreamInfo $resourceStreamInfo = null, |
52
|
|
|
IOperationContext $operationContext, |
53
|
|
|
$relativeUri = null |
54
|
|
|
) { |
55
|
|
|
if (null == $resourceStreamInfo) { |
56
|
|
|
return $relativeUri . '/$value'; |
57
|
|
|
} |
58
|
|
|
return $relativeUri . '/' . $resourceStreamInfo->getName(); |
59
|
|
|
//let library creates default media url. |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.