Skip to content

simplepie/utility-pack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



Utility Pack

A set of small utilities for PHP 7.2+.

Badges

Health

Open Issues Pull Requests Contributors Repo Size GitHub Commit Activity GitHub Last Commit

Quality

Travis branch Coveralls Code Quality Symfony Insight

Social

Author Follow Blog Stars

Compliance

License

Usage

QueryString

Believe it or not, different PHP installations can have different default values for generating query strings. This class uses explicit rules so that query strings are always generated exactly the same way. Leverages http_build_query() under the hood.

<?php
use SimplePie\UtilityPack\Util\QueryString;

echo QueryString::build([
    'limit'  => 'a',
    'order'  => 'b',
    'offset' => 'c',
]);

#=> limit=a&order=b&offset=c

Time

Simple constants for time. Makes time calculations easier to read and understand.

<?php
use SimplePie\UtilityPack\Util\Time;

echo sprintf('%s, %s, %s', 1 * Time::SECOND, 2 * Time::SECONDS, 10 * Time::SECONDS);
#=> 1, 2, 10

echo sprintf('%s, %s, %s', 1 * Time::MINUTE, 2 * Time::MINUTES, 10 * Time::MINUTES);
#=> 60, 120, 600

echo sprintf('%s, %s, %s', 1 * Time::HOUR, 2 * Time::HOURS, 10 * Time::HOURS);
#=> 3600, 7200, 36000

echo sprintf('%s, %s, %s', 1 * Time::DAY, 2 * Time::DAYS, 10 * Time::DAYS);
#=> 86400, 172800, 864000

echo sprintf('%s, %s, %s', 1 * Time::WEEK, 2 * Time::WEEKS, 10 * Time::WEEKS);
#=> 604800, 1209600, 6048000

echo 0.5 * Time::YEAR;
#=> 15778800

You can also use the standard ISO-8601 format, with second granularity, and set to UTC “Zulu” time (using the Z annotation).

<?php
use SimplePie\UtilityPack\Util\Time;

echo gmdate(Time::FORMAT_ISO8601_ZULU);
#=> 2017-05-28T01:46:06Z

Type

You can easily get the scalar type or classname of any object.

<?php
use SimplePie\UtilityPack\Util\Types;

echo Types::getClassOrType(
    new \SimpleXMLElement('<xml/>')
);
#=> SimpleXMLElement

echo Types::getClassOrType(
    new DateTime(
        'now',
        new DateTimeZone('UTC')
    )
);
#=> DateTime

echo Types::getClassOrType('string'));
#=> string

echo Types::getClassOrType(111));
#=> integer

echo Types::getClassOrType(111.0));
#=> double

echo Types::getClassOrType(true));
#=> boolean

echo Types::getClassOrType(false));
#=> boolean

Coding Standards

PSR-1/2/5/12/19 are a solid foundation, but are not an entire coding style by themselves. We automate a large part of our style requirements using PHP CS Fixer and PHP CodeSniffer. (The things that we cannot yet automate are documented in the SimplePie NG Coding Standards.)

These can be applied/fixed automatically by running the (lightweight) linter:

make lint

Additionally, in our quest to write excellent code, we use a variety of tools to help us catch issues with what we've written, including:

Type Description
Linting Tools PHP CS Fixer, PHP CodeSniffer
QA Tools PDepend, PHPLOC, PHP Copy/Paste Detector, PHP Code Analyzer
Static Analysis Phan, PHPStan, Psalm, PHP Dependency Analysis

These reports can be generated by running the (heavyweight) analyzer:

make analyze

Please Support or Sponsor Development

The SimplePie project is a labor of love. Development of the next-generation of SimplePie was started in June 2017 as because it's a project I love, and I believe our community would benefit from this tool.

If you use SimplePie — especially to make money — it would be swell if you could kick down a few bucks. As the project grows, and we start leveraging more services and architecture, it would be great if it didn't all need to come out of my pocket.

You can also sponsor the development of a particular feature. If there's a feature that you want to see implemented, and I believe it's the right fit for the SimplePie project, you can sponsor the development of the feature to get it prioritized.

Your contributions are greatly and sincerely appreciated. See the Sponsor button along the top of the page for more information.