supports( $context ) || ! $this->is_effective( $pack->get_manifest(), $context ) ) { continue; } $pack_id = $pack->get_manifest()->get_id(); $pack_ids[] = $pack_id; foreach ( $pack->get_obligations( $context ) as $obligation ) { if ( ! $obligation instanceof Obligation ) { continue; } $id = $obligation->get_id(); if ( isset( $obligations[ $id ] ) && $obligations[ $id ]->get_value() !== $obligation->get_value() ) { $conflicts[ $id ] = $id; continue; } $obligations[ $id ] = $obligation; } foreach ( $pack->get_overrides( $context ) as $target => $value ) { $overrides[ $target ] = array( 'value' => $value, 'source' => $pack_id, ); } } foreach ( $overrides as $target => $override ) { if ( isset( $obligations[ $target ] ) ) { $obligations[ $target ] = $obligations[ $target ]->with_value( $override['value'], $override['source'] ); unset( $conflicts[ $target ] ); } } return new EffectiveRuleSet( $obligations, array_values( array_unique( $pack_ids ) ), array_values( $conflicts ) ); } private function is_effective( RulePackManifest $manifest, CommerceContext $context ): bool { $occurred_at = $context->temporal()->get_occurred_at(); try { $occurred_at = $occurred_at->setTimezone( new \DateTimeZone( $context->temporal()->get_timezone() ) ); } catch ( \Throwable $exception ) { unset( $exception ); } $date = $occurred_at->format( 'Y-m-d' ); $from = trim( $manifest->get_effective_from() ); $until = trim( (string) $manifest->get_effective_until() ); return ( '' === $from || $date >= $from ) && ( '' === $until || $date <= $until ); } }