| 1 |
<?php |
| 2 |
namespace WPGraphQL\Data\Connection; |
| 3 |
|
| 4 |
/** |
| 5 |
* Class EnqueuedScriptsConnectionResolver |
| 6 |
* |
| 7 |
* @package WPGraphQL\Data\Connection |
| 8 |
* @extends \WPGraphQL\Data\Connection\AbstractConnectionResolver<string[]> |
| 9 |
*/ |
| 10 |
class EnqueuedScriptsConnectionResolver extends AbstractConnectionResolver { |
| 11 |
/** |
| 12 |
* {@inheritDoc} |
| 13 |
*/ |
| 14 |
public function get_ids_from_query() { |
| 15 |
$ids = []; |
| 16 |
$queried = $this->get_query(); |
| 17 |
|
| 18 |
if ( empty( $queried ) ) { |
| 19 |
return $ids; |
| 20 |
} |
| 21 |
|
| 22 |
foreach ( $queried as $key => $item ) { |
| 23 |
$ids[ $key ] = $item; |
| 24 |
} |
| 25 |
|
| 26 |
return $ids; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* {@inheritDoc} |
| 31 |
*/ |
| 32 |
protected function prepare_query_args( array $args ): array { |
| 33 |
return $args; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* {@inheritDoc} |
| 38 |
*/ |
| 39 |
protected function query( array $query_args ) { |
| 40 |
$queue = $this->source->enqueuedScriptsQueue ? $this->source->enqueuedScriptsQueue : []; |
| 41 |
$handles = $query_args['where']['handlesIn'] ?? null; |
| 42 |
|
| 43 |
if ( ! is_array( $handles ) ) { |
| 44 |
return $queue; |
| 45 |
} |
| 46 |
|
| 47 |
return array_values( array_intersect( $queue, $handles ) ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* {@inheritDoc} |
| 52 |
*/ |
| 53 |
protected function loader_name(): string { |
| 54 |
return 'enqueued_script'; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* {@inheritDoc} |
| 59 |
*/ |
| 60 |
protected function max_query_amount(): int { |
| 61 |
return 1000; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* {@inheritDoc} |
| 66 |
* |
| 67 |
* @param ?\_WP_Dependency $model The model to check. |
| 68 |
*/ |
| 69 |
protected function is_valid_model( $model ) { |
| 70 |
return isset( $model->handle ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* {@inheritDoc} |
| 75 |
*/ |
| 76 |
public function is_valid_offset( $offset ) { |
| 77 |
global $wp_scripts; |
| 78 |
return isset( $wp_scripts->registered[ $offset ] ); |
| 79 |
} |
| 80 |
} |
| 81 |
|