-
-
Notifications
You must be signed in to change notification settings - Fork 964
Refactor entities #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor entities #291
Conversation
noplanman
commented
Sep 2, 2016
•
edited
Loading
edited
- Complete rewrite of the Entities, making them more lightweight and almost code-free.
- Methods are now defined by DocBlock comments instead of actual code.
- Magic getters and setters are used for all Entities, including InlineQueryResult objects.
- Updated tests and example code.
- New namespaces for Keyboards and InlineQuery entities.
- New Keyboard and KeyboardButton creation, making it easier to create keyboards.
* origin/master: Ask if a self-signed certificate is being used. [skip ci] Add issue and pull request templates. Update inline comments for hook.php and getUpdatesCLI.php Make sure that logging is set directly after Telegram object initialisation. (thanks @jacklul for pointing this out) Proofread and update utils.md file. Update readme and examples for enableAdmin(s) and add an extra test for string numbers.
* upstream/develop: Added PHP version badge
* upstream/develop: (37 commits) Fix constraint error reported by @jacklul Close php-telegram-bot#289 Small typos and comment corrections. Simplify isAdmin method. Minor fixes. Various little code and comment updates. Refactor JSON entities array string generation. Add new helper method entitiesArrayToJson. Tidy up selectChats method. Tidy up insertEditedMessageRequest method. Tidy up insertMessageRequest method. Tidy up insertCallbackQueryRequest method. Tidy up insertChosenInlineResultRequest method. Tidy up insertInlineQueryRequest method. Tidy up insertChat method. Tidy up insertUser method. Tidy up insertRequest method. Tidy up insertTelegramUpdate method. DRY up getTimestamp method. Tidy up selectMessages method. Tidy up selectTelegramUpdate method. Simplify defineTables method. ...
Update all keyboard commands to follow new structure.
I've just finished an initial version of the keyboard rewrites. Apart from supporting the keyboard object creation as it was till now, I've implemented a faster way of creating standard keyboards: /**
* Gives 2 rows, each with 1 button.
*
* [ Button 1 ]
* [ Button 2 ]
*/
$keyboard = new Keyboard('Button 1', 'Button 2');
/**
* Gives 1 row, with 2 buttons.
*
* [ Button 1 ][ Button 2 ]
*/
$keyboard = new Keyboard(['Button 1', 'Button 2']);
/**
* Gives 2 rows, with 1 and 2 buttons.
*
* [ Button 1 ]
* [ Button 2 ][ Button 3 ]
*/
$keyboard = new Keyboard('Button 1', ['Button 2', 'Button 3']);
// or...
$keyboard = (new Keyboard('Button 1'))
->addRow('Button 2', 'Button 3');
// or with an empty keyboard initialisation...
$keyboard = (new Keyboard([]))
->addRow('Button 1')
->addRow('Button 2', 'Button 3'); Here a few other ways to do the same thing with added properties: $keyboard = new Keyboard(
['text' => 'Send Contact', 'request_contact' => true],
['text' => 'Send Location', 'request_location' => true]
);
$keyboard = new Keyboard(
(new KeyboardButton('Send Contact'))->setRequestContact(true),
(new KeyboardButton('Send Location'))->setRequestLocation(true)
); Changing keyboard properties is easy: $keyboard
->setResizeKeyboard(true)
->setOneTimeKeyboard(true)
->setSelective(false);
$keyboard = Keyboard::forceReply();
$keyboard = Keyboard::hide(); Note: These also return a Same system applies for This isn't 100% done yet and I need to refactor a bit and write the tests, but what do you think of this idea? @akalongman @MBoretto @jacklul |
Hello I would like to address this point: Need to be changed to:
see for example User.php entity |
Conditions like Wherever I check for |
introduce md tryMention Thanks @MBoretto !
…represents a button on it's own row.
Some typos, code cleanup.
Also free some bugs!
* upstream/develop: implement getWebhookInfo method Fix duplicate test case Add test for unit testing class Entitiel/User Move AudioTest.php from tests/Unit* to tests/unit* Fix error importing class TestHelpers Correcting grammatical errors Add unit test for Audio class Add helper method generate fake audio recorded data Add dependency for ext-mbstring, as suggested by @IronLady in php-telegram-bot#92 [skip ci]
Rename stripMarkDown to escapeMarkdown to give it more sense.
Small optimisation for Chat entity.
Save raw JSON response to ServerResponse object.
…ray which will be used for returning JSON string.
Clean out useless code from ServerResponse. Fix ServerResponseTest.