build/GeneratePhonePrefixData.php
private function parseTextFile($filePath, \Closure $handler)
    {
        if (!file_exists($filePath) || !is_readable($filePath)) {
            throw new \InvalidArgumentException("File '{$filePath}' does not exist");
        }

        $data = file($filePath);

        $countryData = array();

        foreach ($data as $line) {
            // Remove \n
            $line = str_replace(array("\n", "\r"), '', $line);
            $line = trim($line);

            if (strlen($line) == 0 || substr($line, 0, 1) == '#') {
                continue;
            }
            if (strpos($line, '|')) {
                // Valid line
                $parts = explode('|', $line);


                $prefix = $parts[0];
                $location = $parts[1];

                $handler($prefix, $location);
            }
        }

        return $countryData;
    }
private function parseTextFile($filePath, \Closure $handler)
    {
        if (!file_exists($filePath) || !is_readable($filePath)) {
            throw new \InvalidArgumentException("File '{$filePath}' does not exist");
        }

        $data = file($filePath);

        $countryData = array();

        foreach ($data as $line) {
            // Remove \n
            $line = str_replace(array("\n", "\r"), '', $line);
            $line = trim($line);

            if (strlen($line) == 0 || substr($line, 0, 1) == '#') {
                continue;
            }
            if (strpos($line, '|')) {
                // Valid line
                $parts = explode('|', $line);


                $prefix = $parts[0];
                $location = $parts[1];

                $handler($prefix, $location);
            }
        }

        return $countryData;
    }
private function parseTextFile ( $ filePath , \ Closure $ handler ) { if ( ! file_exists ( $ filePath ) || ! is_readable ( $ filePath ) ) { throw new \ InvalidArgumentException ( "File '{$filePath}' does not exist" ) ; } $ data = file ( $ filePath ) ; $ countryData = array ( ) ; foreach ( $ data as $ line ) { // Remove \n $ line = str_replace ( array ( "\n" , "\r" ) , '' , $ line ) ; $ line = trim ( $ line ) ; if ( strlen ( $ line ) == 0 || substr ( $ line , 0 , 1 ) == '#' ) { continue ; } if ( strpos ( $ line , '|' ) ) { // Valid line $ parts = explode ( '|' , $ line ) ; $ prefix = $ parts [ 0 ] ; $ location = $ parts [ 1 ] ; $ handler ( $ prefix , $ location ) ; } } return $ countryData ; }
Reads phone prefix data from the provides file path and invokes the given handler for each
mapping read.

@param string $filePath
@param \Closure $handler
@return array
@throws \InvalidArgumentException
Reads phone prefix data from the provides file path and invokes the given handler for each mapping read .