This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Scriptotek\Alma\Bibs; |
||
4 | |||
5 | use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement; |
||
6 | use Scriptotek\Alma\Client; |
||
7 | use Scriptotek\Alma\Exception\NoLinkedNetworkZoneRecordException; |
||
8 | use Scriptotek\Alma\Model\LazyResource; |
||
9 | use Scriptotek\Alma\Users\Requests; |
||
10 | use Scriptotek\Marc\Record as MarcRecord; |
||
11 | use Scriptotek\Sru\Record as SruRecord; |
||
12 | |||
13 | /** |
||
14 | * A single Bib resource. |
||
15 | */ |
||
16 | class Bib extends LazyResource |
||
17 | { |
||
18 | /** @var string */ |
||
19 | public $mms_id; |
||
20 | |||
21 | /* @var Holdings */ |
||
22 | public $holdings; |
||
23 | |||
24 | /* @var Portfolios */ |
||
25 | public $portfolios; |
||
26 | |||
27 | /* @var Representations */ |
||
28 | public $representations; |
||
29 | |||
30 | /* @var ElectronicCollections */ |
||
31 | public $electronic_collections; |
||
32 | |||
33 | /* @var MarcRecord */ |
||
34 | protected $_marc; |
||
35 | |||
36 | /** @var Requests */ |
||
37 | public $requests; |
||
38 | |||
39 | public function __construct(Client $client = null, $mms_id = null) |
||
40 | { |
||
41 | parent::__construct($client); |
||
42 | $this->mms_id = $mms_id; |
||
43 | $this->holdings = Holdings::make($this->client, $this); |
||
44 | $this->portfolios = Portfolios::make($this->client, $this); |
||
45 | $this->representations = Representations::make($this->client, $this); |
||
46 | $this->electronic_collections = ElectronicCollections::make($this->client, $this); |
||
47 | $this->requests = Requests::make($this->client, $this->url('/requests')); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Get the model data. This API does not support JSON for editing, |
||
52 | * so we fetch XML instead. |
||
53 | */ |
||
54 | protected function fetchData() |
||
55 | { |
||
56 | return $this->client->getXML($this->url()); |
||
0 ignored issues
–
show
|
|||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Load MARC record onto this Bib object. Chainable method. |
||
61 | * |
||
62 | * @param string $xml |
||
63 | * |
||
64 | * @return Bib |
||
65 | */ |
||
66 | public function setMarcRecord($xml) |
||
67 | { |
||
68 | $this->_marc = MarcRecord::fromString($xml); |
||
69 | // Note: do not marc as initialized, since we miss some other data from the Bib record. Oh, Alma :/ |
||
70 | |||
71 | return $this; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Initialize from SRU record without having to fetch the Bib record. |
||
76 | * |
||
77 | * @param SruRecord $record |
||
78 | * @param Client|null $client |
||
79 | * |
||
80 | * @return Bib |
||
81 | */ |
||
82 | public static function fromSruRecord(SruRecord $record, Client $client = null) |
||
83 | { |
||
84 | $record->data->registerXPathNamespace('marc', 'http://www.loc.gov/MARC21/slim'); |
||
85 | $mmsId = $record->data->text('.//marc:controlfield[@tag="001"]'); |
||
86 | |||
87 | return (new self($client, $mmsId)) |
||
88 | ->setMarcRecord($record->data->asXML()); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * For backwards-compability. |
||
93 | */ |
||
94 | public function getHoldings() |
||
95 | { |
||
96 | return $this->holdings; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Save the MARC record. |
||
101 | */ |
||
102 | public function save() |
||
103 | { |
||
104 | // If initialized from an SRU record, we need to fetch the |
||
105 | // remaining parts of the Bib record. |
||
106 | $this->init(); |
||
107 | |||
108 | // Inject the MARC record |
||
109 | $marcXml = new QuiteSimpleXMLElement($this->_marc->toXML('UTF-8', false, false)); |
||
110 | $this->data->first('record')->replace($marcXml); |
||
111 | |||
112 | // Serialize |
||
113 | $newData = $this->data->asXML(); |
||
114 | |||
115 | // Alma doesn't like namespaces |
||
116 | $newData = str_replace(' xmlns="http://www.loc.gov/MARC21/slim"', '', $newData); |
||
117 | |||
118 | return $this->client->putXML($this->url(), $newData); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Get the MMS ID of the linked record in network zone. |
||
123 | */ |
||
124 | public function getNzMmsId() |
||
125 | { |
||
126 | // If initialized from an SRU record, we need to fetch the |
||
127 | // remaining parts of the Bib record. |
||
128 | $this->init(); |
||
129 | |||
130 | $nz_mms_id = $this->data->text("linked_record_id[@type='NZ']"); |
||
131 | if (!$nz_mms_id) { |
||
132 | throw new NoLinkedNetworkZoneRecordException("Record $this->mms_id is not linked to a network zone record."); |
||
133 | } |
||
134 | |||
135 | return $nz_mms_id; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Get the Bib of the linked record in network zone. |
||
140 | */ |
||
141 | public function getNzRecord() |
||
142 | { |
||
143 | return $this->client->nz->bibs->get($this->getNzMmsId()); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * Returns the MARC record. Load it if we don't have it yet. |
||
148 | */ |
||
149 | public function getRecord() |
||
150 | { |
||
151 | if (is_null($this->_marc)) { |
||
152 | $this->init(); |
||
153 | } |
||
154 | |||
155 | return $this->_marc; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Called when data is available to be processed. |
||
160 | * |
||
161 | * @param mixed $data |
||
162 | */ |
||
163 | protected function onData($data) |
||
164 | { |
||
165 | $this->setMarcRecord($data->first('record')->asXML()); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Check if we have the full representation of our data object. |
||
170 | * |
||
171 | * @param $data |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | protected function isInitialized($data) |
||
176 | { |
||
177 | return is_a($data, QuiteSimpleXMLElement::class) && $data->has('record'); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Generate the base URL for this resource. |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | protected function urlBase() |
||
186 | { |
||
187 | return "/bibs/{$this->mms_id}"; |
||
188 | } |
||
189 | } |
||
190 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.