HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/official-facebook-pixel/FacebookAds/Object/TargetingSearch.php
<?php
 /*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE file in the root directory of this source tree.
 */

namespace FacebookPixelPlugin\FacebookAds\Object;

use FacebookPixelPlugin\FacebookAds\Api;
use FacebookPixelPlugin\FacebookAds\Cursor;
use FacebookPixelPlugin\FacebookAds\Http\RequestInterface;

class TargetingSearch extends AbstractObject {

  /**
   * @param string $query
   * @param string $type
   * @param string $class
   * @param array $params
   * @param Api $api
   * @return Cursor
   * @throws \InvalidArgumentException
   */
  public static function search(
    $type,
    $class=null,
    $query=null,
    array $params = array(),
    ?Api $api = null) {

    $api = $api ?: Api::instance();
    if (!$api) {
      throw new \InvalidArgumentException(
        'An Api instance must be provided as argument or '.
        'set as instance in the \FacebookAds\Api');
    }

    $params['type'] = $type;
    $params = array_merge($params, array_filter(array(
      'class' => $class,
      'q' => $query,
    )));

    $response = $api->call('/search', RequestInterface::METHOD_GET, $params);
    return new Cursor($response, new TargetingSearch());
  }
}