-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ClassSerialize trait for toArray(), toString() method.
- Loading branch information
Showing
7 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace JiraRestApi; | ||
|
||
trait ClassSerialize | ||
{ | ||
/** | ||
* class property to Array. | ||
* | ||
* @param array $ignoreProperties this properties to be excluded from array. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray($ignoreProperties = []) | ||
{ | ||
$ar = (get_object_vars($this)); | ||
foreach ($ar as $key => $value) { | ||
if (in_array($key, $ignoreProperties)) { | ||
unset($ar[$key]); | ||
} | ||
} | ||
|
||
return $ar; | ||
} | ||
|
||
/** | ||
* class property to String. | ||
* | ||
* @param array $ignoreProperties this properties to be excluded from String. | ||
* | ||
* @return string | ||
*/ | ||
public function toString($ignoreProperties = []) | ||
{ | ||
$ar = $this->toArray($ignoreProperties); | ||
|
||
return json_encode($ar, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters