I need to add the Telegram madelineproto library to my Laravel project. How can I do it via composer and How can I call it in my controllers
composer require danog/madelineproto
https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project
Register \danog\MadelineProto\API class to Laravel Service Container
Or use ready wrapper
https://github.com/setiawanhu/laravel-madeline-proto
You can't add it via composer.
https://packagist.org/packages/danog/madelineproto
It's not a package. It's whole project.
If you look at https://github.com/danog/MadelineProto/blob/master/composer.json
You will see it's not a package.
{
"name": "danog/madelineproto",
"description": "PHP implementation of telegram's MTProto protocol.",
"type": "project",
}
for faster code, use these steps:
Step 1:
download the danog/MadelineProto as a zip file, export the content of the zip file on a folder named 'lib/MadelineProto-master',
Step 2:
use terminal to compose the MadelineProto venders
cd lib/MadelineProto-master
composer install --ignore-platform-reqs
--ignore-platform-reqs is needed to ignore the PHP version and so on.
the composer will download all the vender on lib/MadelineProto-master/vendor
Step 3:
on your controller call the project lib like this:
require_once '../lib/MadelineProto-master/vendor/autoload.php';
//*/
class TelegramController extends Controller
{
private function sendMessage()
{
$settings['app_info']['api_id'] = '##';
$settings['app_info']['api_hash'] = '####';
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
$MadelineProto->start();
$me = $MadelineProto->getSelf();
if (!$me['bot']) {
$sendMessage = $MadelineProto->messages->sendMessage([
'peer' => '#mansourcodes',
'message' => "Hi! <3"
]);
}
}
}
Slow Solution:
this solution will take 3-4s per call:
if (!file_exists('madeline/madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline/madeline.php');
}
require_once 'madeline/madeline.php';
class TelegramController extends Controller
{
// ....
Related
i try to use phpqrcode library in laravel project this package is very popular , this is her link
https://sourceforge.net/projects/phpqrcode/
i use class qrCode in controller but i got this error
message
:
"Class "QRcode" not found"
error when i use phpqrcode class in laravel framework
this is my controller
public function store(Request $request)
{
$input = $request->all();
// include(app_path().'/phpqrcode/qrlib.php');
$code = $request->email ;
$filename ='test' . md5($code) . '.png';
QRcode::png($code, \public_path("temp/$filename"));
$input['qr_code']= $filename;
Participant::create($input);
return response()->json(['status'=>'success','message'=>'participant saved succefully !' ],201);
}
How did you proceed with the installation of the lib into your project?
The lib documentation has some steps that you should follow in order to get started.Please check on the INSTALL FILE.
Personally, I would recommend you use a dependency installed from composer.
Some popular ones can be found at packagist. Try out this as it is well documented
I have a yii project and i would like get groups via mailerlite api.
I cant use package after composer update.
Do you need a conversion within the package?
Thank you for your help.
Sample code:
use MailerLiteApi\MailerLite;
public function actionTeszt() {
$groupsApi = (new MailerLite('XXXXXXX'))->groups();
$allGroups = $groupsApi->get();
print_r($allGroups);
exit;
}
Error
Class 'MailerLiteApi\MailerLite' not found
composer require mailerlite/mailerlite-api-v2-php-sdk && composer update
I tried installing phppresentation library in codeigniter framework. But in codeigniter can't able to use namespace. So how to integrate ?
This probably isn't a 'best practices' example but I got the "Getting Started" example on the PHPPresentation Packagist page to work in CI 3.1.3.
I'm using the default way to use composer as described in the CI manual.
The application and system dirs are up one level from root dir.
The composer.json file is in the application dir.
Cut-n-pasted below from the packagist page into composer.json and ran composer update which saved it into application/vendor/phpoffice.
{
"require": {
"phpoffice/phppresentation": "dev-master"
}
}
In application/libraries created Ppt_stuff.php. Cut-n-pasted Getting Started example into the file. Had to add the class name and function make_ppt. Also fixed the setPath and Save functions path names with realpath('.').
<?php defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
class Ppt_stuff {
public function make_ppt() {
$objPHPPowerPoint = new PhpPresentation();
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
->setDescription('PHPPresentation logo')
->setPath(realpath('.') . '/../application/vendor/phpoffice/phppresentation/samples/resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor(new Color('FFE06B20'));
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(realpath('.') . "/downloads/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(realpath('.') . "/downloads/sample.odp");
}
}
In root directory created /downloads directory.
Added this to the Home controller.
public function use_presentation() {
// load library
$this->load->library('Ppt_stuff');
// call make_ppt
$this->ppt_stuff->make_ppt();
return;
}
Went to http://localhost/home/use_presentation and it created sample.pptx and sample.odp in /downloads.
When I opened them, Powerpoint 2010 complained and offered to fix them.
I've been working with Rachet WebSockets and created a simple chat application. The example uses a WebSocket namespace. This is my first time using namespace. Now I'm trying to add Twilio service but can seem to add Twilio to my namespace.
I know it is autoloaded in the autoload_files.php
<?php
// autoload_files.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
$vendorDir . '/twilio/sdk/Services/Twilio.php',
);
In the composer.json file
{
"autoload": {
"psr-0": {
"Websocket": "src"
}
},
"require": {
"cboden/ratchet": "^0.3.3",
"twilio/sdk": "^4.5"
}
}
I followed the steps from this website : https://www.twilio.com/docs/libraries/php#using-without-composer
I'm calling twilio inside a method of my class like this:
$AccountSid = "xxxxxxxxxxxxxxxxx";
$AuthToken = "xxxxxxxxxxxxxxxxx";
$client = new Client($sid, $token);
$message = $client->account->messages->create(array(
'To' => "+555555555",
'From' => "+555555555",
'Body' => "This is a test",
));
Keep getting this error: Uncaught Error: Class 'Websocket\Client' not found in ......
I'm very new to composer and namespace, hope this is enough information to help me.
I had to update Twilio,
ran composer require twilio/sd
- Removing twilio/sdk (4.12.0)
- Installing twilio/sdk (5.4.1)
Downloading: 100%
Now I'm able to use Twilio\Rest\Client; since it was missing before.
When using namespaces, PHP will always start looking for classes which aren't prepended with their own namespace in the current one.
In your case the current namespace would be Websocket, thus PHP is trying to autoload the class Websocket\Client, to prevent this, you have two options :
1) Tell PHP where to look by using use :
use Twilio\Rest\Client;
2) Prepend the correct namespace
$client = new \Twilio\Rest\Client($sid, $token);
Hi I am new to cassandra database. I am trying to do a project in codeigniter with cassandra database. I have downloaded the phpcassandra files through below link
https://github.com/mauritsl/php-cassandra.
When I am trying to autoload my casssandra.php in codeigniter I got Non-existent class: Cassandra error. Why I got this error and how to solve the issue?
You will need to create a wrapper for it if you wish to use it as a library.
I would suggest you take the composer route.
You can check on packagist for a suitable library.
If you use this particular library phpcassa this is how you would go about getting it to work in Codeigniter.
composer.json
{
"require": {
"php": ">=5.3.0",
"thobbs/phpcassa": "1.1.0"
}
}
index.php
require "../composer/autoload.php";
system/core/codeigniter.php
// Where codeigniter starts to load the Main Controller
// $cassandraDB will be in the GLOBAL scope, so you may want to write a wrapper
$cassandraDB = new ConnectionPool('localhost');
// Then right after this
// if (class_exists('CI_DB') AND isset($CI->db))
// {
// $CI->db->close();
// }
$cassandraDB->close();
User Model
implement it how you wish in your models
public function __construct()
{
//YOU MAY NEED TO PASS $cassandraDB AS A DEPENDANCY!!
$this->users = new ColumnFamily($cassandraDB, 'Standard1');
}