PHPackages                             myvon/devicechanger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. myvon/devicechanger

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

myvon/devicechanger
===================

This package allow to send a link through any method and check if the user has sent the data needed.

1.0(2y ago)03MITPHP

Since Jun 9Pushed 2y ago1 watchersCompare

[ Source](https://github.com/myvon/devicechanger)[ Packagist](https://packagist.org/packages/myvon/devicechanger)[ RSS](/packages/myvon-devicechanger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

devicechanger
=============

[](#devicechanger)

You want your user to send you data through another device (for example a phone) without leaving your page ? This small library help you to !

How it works
============

[](#how-it-works)

This package allow to send a link through any method and check if the user has sent the data needed.

Installation
============

[](#installation)

You can install the package via composer:

```
composer require myvon/devicechanger
```

Creating the file your user is sent to
======================================

[](#creating-the-file-your-user-is-sent-to)

You first need to create the file where your user will be redirected to send the required data.

You can check the `examples/upload.php` file to see an example of a file where the user is invited tu upload a file

Choosing an url generator
=========================

[](#choosing-an-url-generator)

The second step is to choose a way to generate the url to the file. Two generator are provided by default:

- the `Myvon\DeviceChanger\DummyGenerator` which simply return the url with the correct query parameters
- the `Myvon\DeviceChanger\BitlyUrlGenerator` which uses the Bitly service to generate a tiny url and reduce message size (usefull for sms)

For the dummy generator, simply provide the public url to the file :

```
use Myvon\DeviceChanger\DummyGenerator;

$generator = new \Myvon\DeviceChanger\DummyGenerator("http://localhost/upload.php");
```

For the bitly generator, you'll need to provide the public url and your bitly access token :

```
use Myvon\DeviceChanger\DummyGenerator;

$generator = new \Myvon\DeviceChanger\BitlyUrlGenerator("http://localhost/upload.php", "myBitlyAccessToken");
```

Creating your own generator
---------------------------

[](#creating-your-own-generator)

You can create your own generator by implementing the `Myvon\DeviceChanger\UrlGeneratorInterface` interface. You'll simply need to implement the `public function getUrl(string $uid)` method which return the generated url, or false if the generation failed.

Choosing a channel to send the link
===================================

[](#choosing-a-channel-to-send-the-link)

After choosing the generator, you will need to choose through which channel you send the link. Two senders are provided by default:

- The `Myvon\DeviceChanger\DummyGenerator` which will simply save the message and the recipient and always success. He is mainly used to test the library
- The `Myvon\DeviceChanger\OvhSmsGenerator` which send the link by sms using OVH. Be advised that the phone number must start with the country code (+33 for france)

To use the OvhSmsGenerator you'll to provide :

- An `Ovh\Api` instance (which is provided by the official PHP OVH Api available at )
- The sender username you configured in the OVH manager
- The sms service name (starting by `sms-`) provided by OVH.

```
$sender = new \Myvon\DeviceChanger\OvhSmsSender($ovhApi, "MY COMPANY", "sms-xxxxxx-1");
```

Creating a custom channel
-------------------------

[](#creating-a-custom-channel)

You can create a custom channel by implementing the `Myvon\DeviceChanger\SenderInterface` interface. You'll need to implement the two following methods:

- `public function isValid(string $recipient): bool;` which check if the recipient is valid (for example if it is a valid email if you send by mail or a valid phone number for sms channel)
- `public function send(string $recipient, string $message): bool;` which send the $message to the $recipient

Specify the storage
===================

[](#specify-the-storage)

The last step to use the library is to specify how the data are stored and how to check to they have been received.

For now the only storage provided by default is the `Myvon\DeviceChanger\FileStorage` which use the filesystem to store the data (mainly used for upload).

You'll simply need to provide the directory where the data will be stored:

```
$storage = new \Myvon\DeviceChanger\FileStorage('./upload');
```

Adding custom storage
---------------------

[](#adding-custom-storage)

If you need to create a custom storage you can do it by implementing the `Myvon\DeviceChanger\StorageInterface` interface. You'll need to implement the two following methods:

- `public function isReceived(string $uid): bool;` which check if the data are received
- `public function fetch(string $uid);` which return the received data (or a way to access them)

Sending the link
================

[](#sending-the-link)

You can finally use the `Myvon\DeviceChanger\DeviceChanger` class to send the link and check if the data are received.

You will need to provide :

- A class that implements the `Myvon\DeviceChanger\UrlGeneratorInterface` interface
- A class that implements the `Myvon\DeviceChanger\SenderInterface` interface
- A class that implements the `Myvon\DeviceChanger\StorageInterface` interface
- The message sent to the user

The message can be personalized with parameters (see the `send` method bellow) and must contain "%url%" which will be replaced by the generated url.

```
$deviceChanger = new \Myvon\DeviceChanger\DeviceChanger(
    $generator,
    $sender,
    $storage,
    "Pour continuer, veuillez vous rendre à l'adresse %url% (envoyé à %phone%)"
);
```

The parameters must follow this pattern : "%myparameter%"

You can then send the message:

```
if(($uid = $deviceChanger->send("+33600000000"))) {
    // Success
}
```

You can provide your parameters as second argument to the method :

```
$uid = $deviceChanger->send("+33600000000", [
'myparameter' => 'my value',
]); // %myparameter% will be replace by 'my value'
```

Check if the data are received
==============================

[](#check-if-the-data-are-received)

Now the link has been sent, you can check if your user has submitted the data :

```
if($deviceChanger->check($uid)) {
    // Data have been received
}
```

To retrieve the data :

```
$data  = $devicechanger->fetch($uid); // Return false if data not received
```

Note that the `Myvon\DeviceChanger\FileStorage` class will return the full path to the directory where the file(s) have been received.

Examples
========

[](#examples)

You can check the following examples:

- `examples/check.php` which check if the data are received for a given UID then return the data if they have been received or `KO` otherwise.
- `examples/example.php` which contain a full example in one page using the DummyGenerator and the DummySender (can be run in cli)
- `examples/upload.php` which is an example of the file the user is redirected to. It contain a simple upload form allowing the user to upload a file

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1073d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/954447d10f755d5a91a6a68ed467ea6173512d3d9b57e99d2ff34bd1e61ec215?d=identicon)[myvon](/maintainers/myvon)

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/myvon-devicechanger/health.svg)

```
[![Health](https://phpackages.com/badges/myvon-devicechanger/health.svg)](https://phpackages.com/packages/myvon-devicechanger)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
