The Stream Blog

New Zend Framework Module for Integrating Stream

Hot off the heels of our Doctrine ORM integration, we’re ready to announce our next PHP integration! We’ve created a neat little package, which serves as a Zend Framework module! Zend Framework is one of the most popular frameworks in the PHP ecosystem – after Laravel and Symfony, that is. Since we know many of you are using it, we are making it easier for you to get started with Stream in your Zend Framework applications.
 

This new Zend Framework module exposes our lower level Stream PHP client as a pre-configured “service”. This makes it easier to start using since there’s no need to figure out how to setup a client object – use a blank configuration file instead.

Installation

The readme docs are pretty clear, but here’s how you can get started in less than a minute. Run the composer command to install the package:

Next up, tell your application that there’s a new module to load. Add this one line to your config/modules.config.php file:

The last step is to add a new config file to your config/autoload folder. Any file name will do – something like stream.local.php will work fine. You want to set either the URL or the app_key and app_secret variables, depending on your environment. Another option is to use the example below to read from environment variables. These environment variables are used to pass on sensitive information to your application:

Now you’re done!

You like PSR-11 containers?

Having completed the previous steps, you can inject a configured object anywhere. To do that, use the service container which is a PSR-11 interfaced container!

$client = $container->get(GetStream\Stream\Client::class);

So how does it work?

Very simple! In our Zend Framework module, we have a composer.json file. In this file there is a config block which tells your application it can find said module in this package:

"config": {
    "zf": {
        "component": "GetStream\\Stream"
    }
},

And that’s that! Zend automatically finds a GetStream\Stream\Module class and uses that to load the rest of the module.

Very simple, very convenient. Now you can get started with Stream in your Zend Framework application. For more documentation, see our readme file and read our low-level package documentation.

If you’re new to Stream, please visit our Getting Started page for a 5-minute walkthrough. Learn how to build scalable newsfeeds and activity streams in hours rather than months. And, as always, we would greatly appreciate any feedback, bug reports or pull requests!


Also published on Medium.