zendframework / zend-diactoros

PSR-7 HTTP Message implementation
BSD 3-Clause "New" or "Revised" License
1.56k stars 152 forks source link

Extract (private) functionality of ServerRequestFactory to functions #307

Closed weierophinney closed 6 years ago

weierophinney commented 6 years ago

This patch serves as an alternative to #306. It extracts a number of methods from ServerRequestFactory into dedicated functions, allowing them to be used to derive ServerRequest artifacts.

tl;dr: This patch removes all private methods of ServerRequestFactory, and adds the following functions under the Zend\Diactoros namespace:

The full set of changes include:

weierophinney commented 6 years ago

Outstanding questions:

Moln commented 6 years ago

A function suggestion.

https://github.com/zendframework/zend-diactoros/blob/1.7.2/src/ServerRequestFactory.php#L393-L399

public static function stripQueryString($path)
{
        if (($qpos = strpos($path, '?')) !== false) {
            return substr($path, 0, $qpos);
        }
        return $path;
}

There can be simpler code.

public static function stripQueryString($path)
{
        return explode('?', $path, 2)[0];
}
weierophinney commented 6 years ago

Thanks, @Moln ; incorporated both in that method, as well as the inlined version in marshalUriFromSapi().

weierophinney commented 6 years ago

I've made the following changes at this time:

I've also updated ServerRequestFactory to follow all changes.

At this point, I think this is ready for final review.