Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UrlRewrite.php
Go to the documentation of this file.
1 <?php
7 
11 
18 {
22  const URL_REWRITE_ID = 'url_rewrite_id';
23  const ENTITY_ID = 'entity_id';
24  const ENTITY_TYPE = 'entity_type';
25  const IS_AUTOGENERATED = 'is_autogenerated';
26  const REQUEST_PATH = 'request_path';
27  const TARGET_PATH = 'target_path';
28  const STORE_ID = 'store_id';
29  const REDIRECT_TYPE = 'redirect_type';
30  const DESCRIPTION = 'description';
31  const METADATA = 'metadata';
35  protected $defaultValues = [
36  self::REDIRECT_TYPE => 0,
37  self::IS_AUTOGENERATED => 1,
38  self::METADATA => null,
39  self::DESCRIPTION => null,
40  ];
41 
45  private $serializer;
46 
53  public function __construct(
54  $data = [],
55  Json $serializer = null
56  ) {
57  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
58  parent::__construct($data);
59  }
60 
67  public function getByKey($key)
68  {
69  return $this->_get($key);
70  }
71 
75  public function getUrlRewriteId()
76  {
77  return $this->_get(self::URL_REWRITE_ID);
78  }
79 
84  public function setUrlRewriteId($urlRewriteId)
85  {
86  return $this->setData(self::URL_REWRITE_ID, $urlRewriteId);
87  }
88 
92  public function getEntityId()
93  {
94  return $this->_get(self::ENTITY_ID);
95  }
96 
102  public function setEntityId($entityId)
103  {
104  return $this->setData(self::ENTITY_ID, $entityId);
105  }
106 
110  public function getEntityType()
111  {
112  return $this->_get(self::ENTITY_TYPE);
113  }
114 
120  public function setEntityType($entityType)
121  {
122  return $this->setData(self::ENTITY_TYPE, $entityType);
123  }
124 
128  public function getIsAutogenerated()
129  {
130  return $this->_get(self::IS_AUTOGENERATED) === null ?
131  $this->defaultValues[self::IS_AUTOGENERATED] : $this->_get(self::IS_AUTOGENERATED);
132  }
133 
139  public function setIsAutogenerated($isAutogenerated)
140  {
141  return $this->setData(self::IS_AUTOGENERATED, $isAutogenerated);
142  }
143 
147  public function getRequestPath()
148  {
149  return $this->_get(self::REQUEST_PATH);
150  }
151 
157  public function setRequestPath($requestPath)
158  {
159  return $this->setData(self::REQUEST_PATH, $requestPath);
160  }
161 
165  public function getTargetPath()
166  {
167  return $this->_get(self::TARGET_PATH);
168  }
169 
175  public function setTargetPath($targetPath)
176  {
177  return $this->setData(self::TARGET_PATH, $targetPath);
178  }
179 
183  public function getStoreId()
184  {
185  return $this->_get(self::STORE_ID);
186  }
187 
193  public function setStoreId($storeId)
194  {
195  return $this->setData(self::STORE_ID, $storeId);
196  }
197 
201  public function getRedirectType()
202  {
203  return (int)$this->_get(self::REDIRECT_TYPE);
204  }
205 
211  public function setRedirectType($redirectCode)
212  {
213  return $this->setData(self::REDIRECT_TYPE, $redirectCode);
214  }
215 
219  public function getDescription()
220  {
221  return $this->_get(self::DESCRIPTION);
222  }
223 
229  public function setDescription($description)
230  {
231  return $this->setData(self::DESCRIPTION, $description);
232  }
233 
237  public function getMetadata()
238  {
239  $metadata = $this->_get(self::METADATA);
240  return !empty($metadata) ? $this->serializer->unserialize($metadata) : [];
241  }
242 
248  public function setMetadata($metadata)
249  {
250  if (is_array($metadata)) {
251  $metadata = $this->serializer->serialize($metadata);
252  }
253  return $this->setData(UrlRewrite::METADATA, $metadata);
254  }
255 
261  public function toArray()
262  {
263  return array_merge($this->defaultValues, $this->_data);
264  }
265 }
__construct( $data=[], Json $serializer=null)
Definition: UrlRewrite.php:53