/** * Check a string starts with one of the needles provided * * @param $haystack * @param array $needles * @param bool $case * * @return bool * * @deprecated */ function starts_with_any($haystack, array $needles, $case = true) { return \Packaged\Helpers\Strings::startsWithAny($haystack, $needles, $case); }
/** * Is Dispatch responsible for the incoming request * * @param Request $request * * @return bool */ public function isDispatchRequest(Request $request) { $runOn = $this->_config->getItem('run_on', 'path'); switch ($runOn) { case 'path': $match = $this->_config->getItem('run_match', 'res'); return Strings::startsWith($request->getPathInfo() . '/', "/{$match}/"); case 'subdomain': $matchCfg = $this->_config->getItem('run_match', 'static.,assets.'); $subDomains = ValueAs::arr($matchCfg, ['static.']); return Strings::startsWithAny($request->getHost(), $subDomains); case 'domain': $matchCfg = $this->_config->getItem('run_match', null); $domains = ValueAs::arr($matchCfg, []); return Strings::endsWithAny($request->getHttpHost(), $domains, false); } return false; }
/** * Detect if the user is browsing on the private network * * @param string|null $ip IP to test * * @return bool */ public function isPrivateNetwork($ip = null) { if ($ip === null) { $ip = $this->getClientIp(); } return Strings::startsWithAny($ip, ['192.168.', '10.', '172.16.', '127.']); }
include_once dirname(dirname(__DIR__)) . '/vendor/autoload.php'; use Packaged\Helpers\Path; use Packaged\Helpers\Strings; $output = '<?php namespace Fortifi\\FortifiApi\\ActivityFeed\\Enums; class ActivityFeedStoryEnum { public static $storyTypes = [ '; $stories = Path::globRecursive(Path::build(__DIR__, 'Stories')); foreach ($stories as $story) { $story = str_replace(__DIR__ . '/Stories/', '', $story); //Skip Abstracts and Non Story Classes if (Strings::startsWithAny($story, ['Abstract']) || !Strings::endsWith($story, 'Story.php')) { continue; } $part = explode('/', $story); $storyClass = array_pop($part); $storyClass = str_replace('Story.php', '', $storyClass); $storyNs = 'Fortifi\\FortifiApi\\ActivityFeed\\Stories\\' . implode('\\', $part); $key = Strings::stringToUnderScore($storyClass); //Skip Interfaces if (substr($key, 0, 2) == 'i_') { continue; } $output .= " '{$key}' => '" . $storyNs . "\\" . $storyClass . "Story',\n"; } $output .= ' ]; }
/** * Detect if URL has a protocol * * @param string $path * * @return bool */ private function isExternalUrl($path) { return strlen($path) > 8 && Strings::startsWithAny($path, ['http://', 'https://', '//']); }
public function testStartsWithAny() { $this->assertTrue(Strings::startsWithAny("abcdef", ["c", "ab"], true)); $this->assertTrue(Strings::startsWithAny("aBcdef", ["c", "aB"], true)); $this->assertFalse(Strings::startsWithAny("abcdef", ["c", "ef"], true)); $this->assertTrue(Strings::startsWithAny("aBcdef", ["c", "aB"], false)); $this->assertFalse(Strings::startsWithAny("aBcdef", ["c", "ef"], false)); }