SearchEngines class
Framework\Debug\SearchEngines
Class SearchEngines.
Defined in libraries/debug/src/SearchEngines.php
Properties #
- $engines
- Associative array with search engine names as key and their base URLs as value.
- $current
- Name of currently selected search engine.
$engines
protected array $engines = array (
'ask' => 'https://www.ask.com/web?q=',
'baidu' => 'https://www.baidu.com/s?wd=',
'bing' => 'https://www.bing.com/search?q=',
'duckduckgo' => 'https://duckduckgo.com/?q=',
'google' => 'https://www.google.com/search?q=',
'yahoo' => 'https://search.yahoo.com/search?p=',
'yandex' => 'https://yandex.com/search/?text=',
)
Associative array with search engine names as key and their base URLs as value.
$current
protected string $current = 'google'
Name of currently selected search engine.
Methods #
- __construct()
- Instantiate the class and allows you to define the current search engine.
- add()
- -
- getAll()
- Returns the array of search engines.
- getCurrent()
- Returns the name of the current engine.
- getCurrentUrl()
- Returns the base URL of the current engine.
- getUrl()
- Returns the base URL of an engine; throws exception if it does not exist.
- makeLink()
- Generates a search link with the given query, using the current engine or a specific name.
- set()
- Sets a search engine.
- setCurrent()
- Sets the current search engine; validates existence.
- setMulti()
- Set multiple search engines at once.
__construct()
public function __construct(?string $current = NULL, array $engines = array (
))
Instantiate the class and allows you to define the current search engine.
Parameters
- ?string $current - Set the current search engine name or null to use the default
- array $engines - Custom search engines
add()
public function add(string $name, string $url): static
Parameters
- string $name
- string $url
Returns
static
getAll()
public function getAll(): array
Returns the array of search engines.
Returns
array
- search engine names as keys and URLs as values
getCurrent()
public function getCurrent(): string
Returns the name of the current engine.
Returns
string
getCurrentUrl()
public function getCurrentUrl(): string
Returns the base URL of the current engine.
Returns
string
getUrl()
public function getUrl(string $name): string
Returns the base URL of an engine; throws exception if it does not exist.
Parameters
- string $name - The search engine name
Returns
string
- The search engine base URL
makeLink()
public function makeLink(string $query, ?string $name = NULL): string
Generates a search link with the given query, using the current engine or a specific name.
Parameters
- string $query - A string to be URL-encoded
- ?string $name - the search engine name or null to use the current
Returns
string
- Returns the link to search for the exception
set()
public function set(string $name, string $url): static
Sets a search engine.
Parameters
- string $name - The search engine name
- string $url - The search engine base URL
Returns
static
setCurrent()
public function setCurrent(string $name): static
Sets the current search engine; validates existence.
Parameters
- string $name - The search engine name
Returns
static
setMulti()
public function setMulti(array $engines): static
Set multiple search engines at once.
Parameters
- array $engines
Returns
static