1. Go to this page and download the library: Download ionews/light-service-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ionews / light-service-php example snippets
class GenerateRandomPassword extends Action {
protected function perform() {
$length = 8;
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$password = '';
for ($i = 0; $i < $length; $i++) {
$password .= $chars[rand(0, strlen($chars) - 1)];
}
$this->context->password = $password;
}
}
class UpdateUserPassword extends Action {
protected function perform() {
$user_id = $this->context->user_id;
$password = $this->context->password;
// access the database using the method of your choice and update the password
}
}
class UserController extends BaseController {
public function resetPassword() {
$result = ResetUserPassword::execute(['user_id' => $this->request->id]);
if ($result->success()) {
// use $result->getContext() to access the results and redirect the app
} else {
// error, use $result->getFailureMessage() to access any failure message
}
}
}
class UpdateUserPassword extends Action {
protected function perform() {
$user_id = $this->context->user_id;
$password = $this->context->password;
// access the database using the method of your choice and update the password
}
protected function rollback() {
// undo the update password
}
}
class SomeAction extends Action {
protected function before() {
// any setup
}
protected function perform() {
// perform
}
protected function after() {
// cleanup
}
}
class UpdateUserPassword extends Action {
protected $expects = ['user_id', 'password'];
protected function perform() {
$user_id = $this->context->user_id;
$password = $this->context->password;
// access the database using the method of your choice and update the password
}
}
$result = UpdateUserPassword::execute(['user_id' => 1]);
$result->success(); // false
$result->getFailureMessage(); // 'Expectations were not met'