/** * Find the map type based on the provided object * * @param $object * * @return string */ public function lookupMapType($object) { $reflection = new \ReflectionObject($object); $filename = $reflection->getFileName(); //Find the common start to the filename of the callee and this file, which //is known to be in the vendor directory $prefix = Strings::commonPrefix($filename, $this->ownFile()); //Account for other packaged repos that may offer resources if (Strings::endsWith($prefix, 'packaged' . DIRECTORY_SEPARATOR)) { $prefix = substr($prefix, 0, -9); } //Calculate the vendor and package names if (Strings::endsWith($prefix, 'vendor' . DIRECTORY_SEPARATOR)) { $path = substr($filename, strlen($prefix)); $this->_lookupParts = array_slice(explode('/', $path, 3), 0, 2); return DirectoryMapper::MAP_VENDOR; } return DirectoryMapper::MAP_SOURCE; }
public function testCommonPrefixNotStoppingOnInts() { $expectations = [["123abc", "123def", "123"], ["abc1", "abc2", "abc"], ["abc1", "abd2", "ab"], ["serverName1", "serverName2", "serverName"]]; foreach ($expectations as $expect) { $this->assertEquals($expect[2], \Packaged\Helpers\Strings::commonPrefix($expect[0], $expect[1], false)); } }