PHP - - By Bruno Skvorc

Sourcehunt – Build a Medium Exporter + Cool New Libs!

It’s time for our monthly hunt for new open source libraries to use and contribute to!

If you’re new to Sourcehunt, it’s our monthly post for promoting open source projects that seem interesting or promising and could use help in terms of Github stars or pull requests.

It’s our way of giving back – promoting projects that we use (or could use) so that they gain enough exposure to attract a wider audience, a powerful community and, possibly, new contributors or sponsors.

Sourcehunt logo

We’ve had a lot of fantastic submissions this month, so let’s dive in!


rethinkphp/json-validator [28 ★]

A Json Validator that designed to be elegant and easy to use.

Made by the author of the Blink framework, json-validator’s only purpose is to make sure a data structure conforms to the pre-defined specification. It currently supports int, double, bool, string, number, array, and object, but also lets you define fully custom types, like so:

$validator->defineType('User', [
    'name' => 'string',
    'gender' => 'string',
    'age' => '?integer',
]);

You can also define them in callables:

$validator->defineType('timestamp', function ($value) {
    if ((!is_string($value) && !is_numeric($value)) || strtotime($value) === false) {
        return false;
    }

    $date = date_parse($value);

    return checkdate($date['month'], $date['day'], $date['year']);
});

The library is very new and could use contributions – everything from the docs to features needs work, so it’s a great opportunity to contribute.


Nerdmind/Blog [20 ★]

This minimalistic and mobile-friendly blogging engine, while leaving much to be desired in the visual department, is a practical quick-fix for anyone looking to start a blog without the baggage of larger system weighing them down.

It does seem somewhat like a learning experience for the author, so why not jump in, identify some issues (lots of antipatterns right off the bat), and maybe fix some while you’re at it? Perhaps both of you can learn from the experience.


violet-php/streaming-json-encoder [125 ★]

This streaming JSON encoder lets you process and send large JSON files without hitting the memory limit. As described in the README:

Streaming JSON Encoder is a PHP library that provides a set of classes to help with encoding JSON in a streaming manner, i.e. allowing you to encode the JSON document bit by bit rather than encoding the whole document at once. Compared to the built in json_encode function, there are two main advantages:

  • You will not need to load the entire data set into memory, as the encoder supports iterating over both arrays and any kind of iterators, like generators, for example.
  • You will not need to load the entire resulting JSON document into the memory, since the JSON document will be encoded value by value and it’s possible to output the encoded document piece by piece.

It also provides a PSR-7 compatible stream for those kinds of frameworks.

The package could use more tutorials, tests, and usage examples, so get on it if you’re eager – we’ll pay!


dsentker/phpinsights [2 ★]

This simple but effective wrapper around Google PageSpeed Insights is incredibly useful for testing pipelines when you want to track your pagespeed score across time or commit.

$uri = 'http://example.com';
$caller = new \PhpInsights\InsightsCaller('your-google-api-key-here', 'de');
$response = $caller->getResponse($uri, \PhpInsights\InsightsCaller::STRATEGY_MOBILE);
$result = $response->getMappedResult();

var_dump($result->getSpeedScore()); // 100 
var_dump($result->getUsabilityScore()); // 100 

Note that you need to get an API key from the Google Dev console before you can use it.

Right now, it needs more tests, so if your TDD-fu is weak, here’s a chance to refresh it!


lazychaser/laravel-nestedset [847 ★]

A fairly popular library already, laravel-nestedset provides Laravel users with a very approachable and incredibly versatile solution to working with nested sets.

As the repo states, it is a way to effectively store hierarchical data in a relational table, and shows good performance when tree is updated rarely. It is tuned to be fast for getting related nodes and ideally suited for building multi-depth menus or categories for shops.

The library is feature-rich, including but not limited to reversed tree retrieval, appending and prepending to any parent level, dealing with siblings, flattening, and more.

Right now, it has 15 issues that need attention – go and give them a hand if you can, will you?


jmespath/jmespath.php [238 ★]

While we’re still on the JSON train, let’s hop onto this wagon.

This package by Michael Dowling of Guzzle fame allows you to “declaratively specify how to extract elements from a JSON document“. Here’s what this means exactly, in code:

$expression = 'foo.*.baz';

$data = [
    'foo' => [
        'bar' => ['baz' => 1],
        'bam' => ['baz' => 2],
        'boo' => ['baz' => 3]
    ]
];

JmesPath\search($expression, $data);
// Returns: [1, 2, 3]

Essentially, you define expressions via which you can traverse and extract very complex JSON structures with little to no effort.

There are some outstanding issues and pull requests one could look at, but we’re more interested in paying you for intricate usage examples. Dive in!


lubusIN/laravel-decomposer [182 ★]

Like the README succinctly puts it:

Laravel Decomposer decomposes and lists all the installed packages and their dependencies along with the Laravel & the Server environment details your app is running in. Decomposer also generates a markdown report from those details that can be used for troubleshooting purposes, also it allows you to generate the same report as an array anywhere in your code.

While definitely a niche product, this package will no doubt find its use in various non-technical scenarios where a project’s dependency setup needs to be shared with clients or development teams, where server environment variables are not obvious and need to be exposed, when users collect bug contexts, and more – a simple exposed endpoint publishing this data would provide answers to many questions developers simply must ask their clients when debugging.

I can see it as being especially useful in Laravel-based CMS contexts where plugins and other details could be buried under hundreds of other packages.

There’s some todos on the roadmap, so go get some!


tightenco/jigsaw [532 ★]

A static site generator powered by Laravel’s Blade. Jigsaw is like Sculpin or Spress, but built on Laravel instead of on Symfony – which means support for Blade plugins and syntax, and elixir for building assets. Jigsaw also supports Markdown, much like its competitors.

There are some issues and PRs to take care of, and their documentation is lacking as well, so get to it! Also, we need some tutorials about it!


slevomat/coding-standard [93 ★]

This coding standard is an extension of the PHP_CodeSniffer Consistence Coding Standard and adds some useful sniffs on top of what’s already there.

It’d be futile to list them all here when they’re so well described in the README – go check! The sniffs are selective, so you can choose not to use those that don’t apply to your project. Most, however, are very handy cross-project rules that every professional dev team should readily enforce.

Go star it and add it to your development environment and testing pipeline today!


BrainMaestro/composer-git-hooks [95 ★]

Manage git hooks easily in your composer configuration. This package makes it easy to implement a consistent project-wide usage of git hooks. Specifying hooks in the composer file makes them available for every member of the project team. This provides a consistent environment and behavior for everyone.

If you’re not familiar with a git-hooks-based workflow, we recommend this post and suggest you follow up with any of these – you’ll quickly find that they’re incredibly useful.

This package makes their maintenance and managing much easier.


That’s it for March. Found anything you could sink your teeth into?

As always, please throw your links at us with the #sourcehunt hashtag! If you build something with the projects we’ve mentioned, or if you submit an elaborate pull request you’d like to talk about, give us a shout and we’ll make sure the world knows about it!

Like last time, (that challenge remains unclaimed, by the way – there’s $500 in it for you if you do it!), we’re using the above packages for inspiration on creating a potentially useful app:

App+Tutorial idea of the month: Build an app which takes a Medium data export in zip format, processes it internally, turns it into JSON with the Streaming JSON library and verifies that JSON with the validator, and then converts this JSON into a format usable by either NerdMind/Blog or TigthenCo/Jigsaw (user chooses). The project needs to be sniffed with Slevomat/coding-standard, preferrably automatically, and there needs to be a UI in which users can load the aforementioned JSON format (again use the Streaming lib) and apply extraction expressions with jmespath.php to get some data out. Get in touch to find out how much this is worth to us!

Happy coding!

Sponsors
Login or Create Account to Comment
Login Create Account