ActionScheduler_ScheduleDeserializer::deserialize
Perform the two-pass deserialization for this instance's already-validated blob.
Method of the class: ActionScheduler_ScheduleDeserializer{}
No Hooks.
Returns
ActionScheduler_Schedule|false.
Usage
// private - for code of main (parent) class only $result = $this->deserialize();
ActionScheduler_ScheduleDeserializer::deserialize() ActionScheduler ScheduleDeserializer::deserialize code WC 11.2.1
private function deserialize() {
// Initial attempt to unserialize, specifying all trusted classes: for default actions using
// supplied schedule classes, this should succeed without any problems. Otherwise, the result
// may contain one or more __PHP_Incomplete_Class references that we will need to examine.
$all_trusted_classes = array_merge( $this->allowed_scheduler_classes, $this->allowed_nested_classes );
$candidate = @unserialize( $this->source_data, array( 'allowed_classes' => $all_trusted_classes ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize, WordPress.PHP.NoSilencedErrors.Discouraged
// A schedule is always an object graph.
if ( ! is_object( $candidate ) ) {
return false;
}
$this->outer_class = $this->class_name_of( $candidate );
// Verify that we have a valid schedule representation, scanning for disallowed nested classes.
if ( ! $this->is_schedule_implementation( $this->outer_class ) || ! $this->scan_object_graph( $candidate, true, 0 ) ) {
return $this->reject( $this->outer_class, false );
}
// If the candidate is an acceptable schedule class, and doesn't contain any potential offenders, it is safe.
if ( ! $candidate instanceof __PHP_Incomplete_Class && empty( $this->potential_offenders ) ) {
return $candidate;
}
// Otherwise the top-level object is itself a valid schedule, but references one or more disallowed classes.
foreach ( $this->potential_offenders as $offender ) {
if ( ! $this->is_allowed_nested_class( $offender, $this->allowed_nested_classes ) ) {
return $this->reject( $offender, true );
}
}
// If we reach this point, any potential offenders must in fact be safe.
$allowed = array_values(
array_unique(
array_merge( $all_trusted_classes, array( $this->outer_class ), $this->potential_offenders )
)
);
// Re-run unserialize.
return @unserialize( $this->source_data, array( 'allowed_classes' => $allowed ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize, WordPress.PHP.NoSilencedErrors.Discouraged
}