/** * pref regex pattern optimize function for rpc package. does clean up, quote and compile to valid regex pattern * from string or array * * @error 13905 * @param string|array $mixed expects regex pattern as string or array * @return string */ public static function regex($mixed) { if (!is_array($mixed)) { $mixed = array($mixed); } foreach ($mixed as &$m) { $m = str_replace(array('\\', '|'), array('\\\\', '\\|'), trim((string) $m)); $m = xapp_regex_delimit($m, '^$'); } return '=^(' . implode('|', $mixed) . ')=i'; }
/** * check if service (class/method or function) in rpc requested calls exists either by checking against name or regex * or index when in batched request. will return either boolean false if not found or the service name as string * if found * * @error 14222 * @param int|string $mixed expects either the index or service name to look for * @return bool|string */ public function hasService($mixed) { if (is_int($mixed)) { return array_key_exists($mixed, $this->_services) ? $this->_services[$mixed] : false; } else { foreach ($this->_services as $service) { if (stristr($service, $mixed) !== false || (bool) @preg_match("/" . xapp_regex_delimit($mixed) . "/i", $service) !== false) { return $service; } } } return false; }