Download the PHP package brandonhudson/lightning without Composer

On this page you can find all versions of the php package brandonhudson/lightning. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lightning

Lightning - MQTT Client

Total Downloads License

Overview

Lightning is a PHP micro framework that lets you quickly connect, publish, and subscribe to MQTT topics.

Features:

Installation

System Requirements

How to Install Lightning

We recommend that you install Lightning with the Composer dependency manager, using:

Require the Composer autoloader into your PHP script, and you are ready to start using it.

Usage

Connection

In order to connect to an MQTT broker, you'll need to initialize a new Lightning\App object with the following parameters:

Parameter Type Default Description
host string (none) The MQTT broker you want to connect to
port integer (none) The port that the MQTT Broker is running on
clientID string (none) The client ID for the connection you're establishing. This should be unique for each connection
username string '' The username for the broker. This is optional.
password string '' The password for the broker. This is optional.

Example:

Publishing

To publish with Lightning, you'll need to have a connection to your MQTT broker already established. Publishing to a topic includes the following parameters:

Parameter Type Default Description
topic string (none) The topic to publish to
message string (none) The message you want to publish
qos integer 0 The quality of service level you want for the published message. (0=at most once, 1=at least once, 2=exactly once). Learn more

Example:

Subscribing

Overview

Lightning offers you a powerful way to quickly subcribe and react to messages sent on specific topics. Modeled after the Slim PHP Framework, Lightning subscriptions are designed in a callback pattern, where a function is invoked when a message is recieved on the subscribed topic.

Topics

Lightning supports topics that use the / seperator for logical components of the topic. Example:

While this does narrow the possibilities for how you can structure your topics, we do this to allow you to parse variables out of the topic after it has been subscribed to (see below).

Inline Variables

Lightning supports inline variable declaration right inside of the topic, allowing you to easily parse variables out of the response when a message is received. In order to declare a variable, you include the + operator along with the variable name (ex: +id) in between two forward slashes.

Example:

As with standard variable naming conventions, inline variables need to have unique names within a single topic (you cannot reuse the same variable name twice in a single topic). If you misformat a route, Lightning will throw a Lightning\Exception\RouteException detailing the problem.

Wildcards

Lightning also supports wildcard topic delcarlation, allowing you to recieve messages on a topic that does not have a fixed topic structure. Per the MQTT specification, wildcards are only available at the end of the topic - you cannot include a wildcard in the middle of a topic. A wildcard is denoted using the # symbol. Example:

If you misuse a wildcard in your topic, Lightning will throw a Lightning\Exception\RouteException detailing the problem.

Mixed Uses

Lightning topics can include both inline variables and wildcards in a topic. Example:

Callbacks

Lightning uses callback methods to invoke code when a message is received for a specific topic. A callback can be defined inline as an anonymous function when you subscribe to a topic, or you can pass the string name function that should be invoked - any function that will return true to is_callable() will work.

The callback function takes one argument, $response, which is a Lightning\Response object (see below for more details on interacting with responses)

Implementation

To subscribe to a route with Lightning, you need to call the subscribe() function with the following parameters:

Parameter Type Default Description
topic string (none) The topic you want to subscribe to with any inline variables or wildcards you want to use.
qos integer 0 The quality of service level you want for the published message. (0=at most once, 1=at least once, 2=exactly once). Learn more
callback string (none) The callback you want to be invoked upon recieving a message.

Example:

Working with Responses

Lightning responses are modeled closely after PSR HTTP responses, including a number of useful methods for retrieving information about the message you receive.

Methods
Method Parameters Returns Description
getMessage() (none) string Returns the message recieved.
getRoute() (none) string Returns the full topic that we received a message on
getReceived() (none) integer Returns the UNIX timestamp that the message was received
attr() $key string/null Fetches the value of that attribute from the topic (used for getting inline variable values)
getAttributes() (none) array Gets all the attributes parsed out of the response topic
hasAttr() $key boolean Returns whether the response has a value for a specific key
getWildcard() (none) string/null Returns the wildcard portion of the topic if one is defined
hasWildcard() (none) boolean Returns whether the response has a wildcard defined
getSubscribedTopic() (none) Lightning\Topic Returns the original topic object that we constructed for the subscription
Example

Contributing

If you find a problem with the Lightning implementation, please open an issue. Improvements and suggestions are welcome - feel free to open a pull request!

License

MIT License

Copyright (c) 2017 Brandon Hudson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Based on the work of Andrew Milsted and the phpMQTT project


All versions of lightning with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brandonhudson/lightning contains the following files

Loading the files please wait ....