UnserializeApi.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Brumann\Polyfill\Unserialize;
  4. /**
  5. * Class UnserializeApi.
  6. */
  7. class UnserializeApi
  8. {
  9. /**
  10. * Unserialize content using Brummann\Polyfill\Unserialize.
  11. *
  12. * @param string $type
  13. * @param string $serialized
  14. * @param bool $ignoreErrors. Optional.
  15. *
  16. * @return mixed
  17. */
  18. public static function unserialize($type, $serialized, $ignoreErrors = false)
  19. {
  20. $allowedClasses = [];
  21. switch ($type) {
  22. case 'career':
  23. case 'sequence_graph':
  24. $allowedClasses = [
  25. \Fhaculty\Graph\Graph::class,
  26. \Fhaculty\Graph\Set\VerticesMap::class,
  27. \Fhaculty\Graph\Set\Vertices::class,
  28. \Fhaculty\Graph\Set\Edges::class,
  29. \Fhaculty\Graph\Vertex::class,
  30. \Fhaculty\Graph\Edge\Base::class,
  31. \Fhaculty\Graph\Edge\Directed::class,
  32. \Fhaculty\Graph\Edge\Undirected::class,
  33. ];
  34. break;
  35. case 'course':
  36. $allowedClasses = [
  37. \Chamilo\CourseBundle\Component\CourseCopy\Course::class,
  38. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Announcement::class,
  39. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Asset::class,
  40. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Attendance::class,
  41. \Chamilo\CourseBundle\Component\CourseCopy\Resources\CalendarEvent::class,
  42. \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyLearnpath::class,
  43. \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyTestCategory::class,
  44. \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseDescription::class,
  45. \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseSession::class,
  46. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Document::class,
  47. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Forum::class,
  48. \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumCategory::class,
  49. \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumPost::class,
  50. \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumTopic::class,
  51. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Glossary::class,
  52. \Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup::class,
  53. \Chamilo\CourseBundle\Component\CourseCopy\Resources\LearnPathCategory::class,
  54. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Link::class,
  55. \Chamilo\CourseBundle\Component\CourseCopy\Resources\LinkCategory::class,
  56. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Quiz::class,
  57. \Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestion::class,
  58. \Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestionOption::class,
  59. \Chamilo\CourseBundle\Component\CourseCopy\Resources\ScormDocument::class,
  60. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Survey::class,
  61. \Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyInvitation::class,
  62. \Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyQuestion::class,
  63. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Thematic::class,
  64. \Chamilo\CourseBundle\Component\CourseCopy\Resources\ToolIntro::class,
  65. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Wiki::class,
  66. \Chamilo\CourseBundle\Component\CourseCopy\Resources\Work::class,
  67. \Chamilo\CourseBundle\Entity\CLpCategory::class,
  68. stdClass::class,
  69. Category::class,
  70. AttendanceLink::class,
  71. DropboxLink::class,
  72. Evaluation::class,
  73. ExerciseLink::class,
  74. ForumThreadLink::class,
  75. LearnpathLink::class,
  76. LinkFactory::class,
  77. Result::class,
  78. StudentPublicationLink::class,
  79. SurveyLink::class,
  80. ];
  81. // no break
  82. case 'lp':
  83. $allowedClasses = array_merge(
  84. $allowedClasses,
  85. [
  86. learnpath::class,
  87. learnpathItem::class,
  88. aicc::class,
  89. aiccBlock::class,
  90. aiccItem::class,
  91. aiccObjective::class,
  92. aiccResource::class,
  93. scorm::class,
  94. scormItem::class,
  95. scormMetadata::class,
  96. scormOrganization::class,
  97. scormResource::class,
  98. Link::class,
  99. LpItem::class,
  100. ]
  101. );
  102. break;
  103. case 'not_allowed_classes':
  104. default:
  105. $allowedClasses = false;
  106. }
  107. if ($ignoreErrors) {
  108. return @Unserialize::unserialize(
  109. $serialized,
  110. ['allowed_classes' => $allowedClasses]
  111. );
  112. }
  113. return Unserialize::unserialize(
  114. $serialized,
  115. ['allowed_classes' => $allowedClasses]
  116. );
  117. }
  118. }