├── .env.example ├── .gitignore ├── CITATION.cff ├── LICENSE.md ├── README.md ├── app ├── Action │ └── Start.php ├── Kernel.php └── Model │ └── User.php ├── composer.json ├── composer.lock ├── index.php └── system ├── Database ├── DBConnection │ └── DBConnection.php ├── ORM │ └── Model.php └── Traits │ ├── HasAttributes.php │ ├── HasCRUD.php │ ├── HasMethodCaller.php │ ├── HasQueryBuilder.php │ ├── HasRelation.php │ └── HasSoftDelete.php ├── Helpers └── coreHelper.php ├── Kernel └── Traits │ └── HasAttribute.php └── TeleCore ├── Class ├── Animation.php ├── Audio.php ├── CopyMessage.php ├── CopyMessages.php ├── Document.php ├── ForwardMessage.php ├── ForwardMessages.php ├── GetUserProfilePhotos.php ├── Message.php ├── Photo.php ├── SendChatAction.php ├── SendContact.php ├── SendDice.php ├── SendLocation.php ├── SendMediaGroup.php ├── SendPaidMedia.php ├── SendPoll.php ├── SendVenue.php ├── SetMessageReaction.php ├── Video.php └── VideoNote.php └── Traits ├── Caller.php ├── Request.php └── Setters.php /.env.example: -------------------------------------------------------------------------------- 1 | # Application environment (e.g., development, production). 2 | APP_ENV=development 3 | 4 | # Telegram bot token for authentication. 5 | TOKEN=68236902417:AAHKhC31rXafoK9liCfHl4bhSC8KKS3NLZgc 6 | 7 | # Database server location. 8 | DB_HOST=localhost 9 | 10 | # Database name. 11 | DB_NAME=framebot 12 | 13 | # Database username. 14 | DB_USERNAME=root 15 | 16 | # Database user password. 17 | DB_PASSWORD= 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | .env -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use FrameBot in your work, please cite this software." 3 | title: "FrameBot: PHP Telegram-Bot Framework" 4 | version: "v0.9.0" # ← use the tag of your latest GitHub release 5 | doi: "10.5281/zenodo.XXXXXXX" # ← Zenodo will give you this on first release 6 | date-released: 2025-05-10 # ← release date that matches your tag 7 | url: "https://github.com/alirezajavadigit/framebot" 8 | repository-code: "https://github.com/alirezajavadigit/framebot" 9 | license: "MIT" 10 | commit: "abcdef1" # ← the git SHA that matches the release 11 | keywords: 12 | - php 13 | - telegram 14 | - bot 15 | - framework 16 | authors: 17 | - family-names: Javadi 18 | given-names: Ali Reza 19 | orcid: "https://orcid.org/0000-0000-0000-0000" 20 | affiliation: "Tehran Institute of Technology" 21 | preferred-citation: 22 | type: software 23 | title: "FrameBot: PHP Telegram-Bot Framework" 24 | version: "v0.9.0" 25 | doi: "10.5281/zenodo.XXXXXXX" 26 | url: "https://github.com/alirezajavadigit/framebot" 27 | authors: 28 | - family-names: Javadi 29 | given-names: Ali Reza 30 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2023 alirezajavadi 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FrameBot – PHP Telegram Bot Framework 2 | 3 | **FrameBot is a lightweight PHP Telegram Bot framework that helps you build, test and deploy bots fast with Composer, PSR‑12 tooling and typed middleware.** 4 | 5 | [![Version](https://img.shields.io/badge/version-2.13.0-blue.svg)](https://github.com/alirezajavadigit/framebot) 6 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 7 | [![GitHub Stars](https://img.shields.io/github/stars/alirezajavadigit/framebot.svg?style=social)](https://github.com/alirezajavadigit/framebot/stargazers) 8 | 9 | 10 | > **Fast** · **Secure** · **Eloquent-style ORM** · **Telegram API First** 11 | 12 | ## 📺 Getting Started Video 13 | [![FrameBot Tutorial](https://i.pcmag.com/imagery/articles/02stCRlZlZJudzKvwJ29HQO-1..v1569484288.jpg)](https://www.youtube.com/watch?v=sEf4MRW0YiE "Watch FrameBot Tutorial") 14 | 15 | ## ✨ Key Features 16 | 17 | ### 🗄️ Database Superpowers 18 | - **Eloquent-style ORM** - Familiar Active Record implementation 19 | ```php 20 | $user = User::find(1)->update(['username' => 'framebot_user']); 21 | - **Migrations System** - Version-controlled database schema management 22 | - **Relationship Support** - HasMany, BelongsTo, Polymorphic relations 23 | 24 | ## 🤖 Telegram Integration 25 | - **Auto-Send Architecture** - RAII pattern for seamless API calls 26 | ```php 27 | Message::chatId($this->chatID)->text("welcome to my telegram bot"); 28 | // Automatically sends on destruct 29 | ``` 30 | ### 25+ API Components - Pre-built classes for: 31 | - 📍 Locations & Venues 32 | - 🎲 Interactive Dice/Polls 33 | - 💌 Media Groups & Paid Content 34 | - 🎭 Message Reactions 35 | ### 🛡️ Security First 36 | - Dotenv Implementation - Secure credential management 37 | - Auto-Sanitization - Built-in parameter validation 38 | - Request Throttling - Protection against API abuse 39 | ### **Section 3: Quick Start** 40 | 41 | ## 🚀 Quick Start 42 | 43 | ### Requirements 44 | - PHP 8.0+ 45 | - Composer 46 | - MySQL 47 | 48 | ### Installation 49 | ```bash 50 | git clone https://github.com/alirezajavadigit/framebot.git 51 | cd framebot 52 | composer install 53 | cp .env.example .env 54 | ``` 55 | ### Configuration (.env) 56 | ```ini 57 | # Telegram Configuration 58 | TOKEN=your_bot_token_here 59 | APP_ENV=production 60 | 61 | # Database Settings 62 | DB_HOST=127.0.0.1 63 | DB_NAME=framebot 64 | DB_USERNAME=root 65 | DB_PASSWORD= 66 | ``` 67 | ### **Section 5: Contributing & Community** 68 | ## 🤝 Contributing 69 | 70 | We welcome contributions! Please follow these steps: 71 | 72 | 1. Fork the repository 73 | 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 74 | 3. Commit changes (`git commit -m 'Add some amazing feature'`) 75 | 4. Push to branch (`git push origin feature/amazing-feature`) 76 | 5. Open a Pull Request 77 | 78 | **Contribution Guidelines**: 79 | - Follow PSR-12 coding standards 80 | - Include PHPDoc comments 81 | - Add unit tests for new features 82 | - Update documentation accordingly 83 | 84 | ## 🌍 Community 85 | 86 | - [GitHub Discussions](https://github.com/alirezajavadigit/framebot/discussions) - Q&A and general help 87 | - [Telegram Channel](https://t.me/framebot_community) - Announcements & updates & Q&A 88 | ## 📜 License 89 | 90 | MIT License - See [LICENSE](LICENSE) for full text 91 | 92 | **Created with ❤️ by [Alireza Javadi](https://github.com/alirezajavadigit)** 93 | **Part of the Open Source Telegram Bot Ecosystem** 🤖 94 | -------------------------------------------------------------------------------- /app/Action/Start.php: -------------------------------------------------------------------------------- 1 | text == "/start") { 35 | Message::chatId($this->chatID)->text("hi thank you for using my framework renew All"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Kernel.php: -------------------------------------------------------------------------------- 1 | setAttribute($content); 39 | 40 | // Register actions to handle incoming requests. 41 | $this->registerActions(); 42 | } 43 | 44 | /** 45 | * Register actions for handling incoming requests. 46 | * 47 | * This method is responsible for registering actions. It starts the action 48 | * registration process by calling the 'start' method. Ensure that necessary 49 | * actions are executed during initialization. 50 | */ 51 | protected function registerActions() 52 | { 53 | // Start the action registration process. 54 | $this->start(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/Model/User.php: -------------------------------------------------------------------------------- 1 | load(); 36 | 37 | // Display errors if the application is in development mode. 38 | if (env("APP_ENV") === "development") { 39 | // Set PHP to display errors. 40 | ini_set("display_errors", "on"); 41 | 42 | // Report all errors. 43 | error_reporting(E_ALL); 44 | } 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Defining API URL 49 | |-------------------------------------------------------------------------- 50 | | 51 | | Define a constant API_URL by concatenating it with the token retrieved 52 | | from the environment variables. 53 | | 54 | */ 55 | define('API_URL', 'https://api.telegram.org/bot' . env('TOKEN') . '/'); 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Retrieving Raw Input Data 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Get the raw POST data from the input stream. 63 | | 64 | */ 65 | $content = file_get_contents("php://input"); 66 | 67 | /* 68 | |-------------------------------------------------------------------------- 69 | | Instantiating Kernel Class 70 | |-------------------------------------------------------------------------- 71 | | 72 | | Instantiate the Kernel class, passing in the raw input data. 73 | | 74 | */ 75 | $Kernel = new Kernel($content); 76 | -------------------------------------------------------------------------------- /system/Database/DBConnection/DBConnection.php: -------------------------------------------------------------------------------- 1 | dbConnection(); 29 | } 30 | 31 | // Return the singleton instance 32 | return self::$dbConnectionInstance; 33 | } 34 | 35 | /** 36 | * Establishes a new database connection. 37 | * 38 | * @return PDO|false The PDO instance representing the database connection, or false on failure 39 | */ 40 | private function dbConnection() 41 | { 42 | // Set PDO options for error handling and result fetching 43 | $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); 44 | 45 | try { 46 | // Attempt to establish a new PDO connection using database credentials 47 | return new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USERNAME, DB_PASSWORD, $options); 48 | } catch (PDOException $e) { 49 | // Handle any exceptions that occur during database connection 50 | echo "Error in database connection: " . $e->getMessage(); 51 | return false; 52 | } 53 | } 54 | 55 | /** 56 | * Retrieves the last inserted ID from the database connection. 57 | * 58 | * @return string The last inserted ID 59 | */ 60 | public static function newInsertId() 61 | { 62 | // Get the last inserted ID from the database connection 63 | return self::getDBConnectionInstance()->lastInsertId(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /system/Database/ORM/Model.php: -------------------------------------------------------------------------------- 1 | inCastsAttributes($attribute) == true ? $object->$attribute = $this->castDecodeValue($attribute, $value) : $object->$attribute = $value; 26 | } 27 | 28 | /** 29 | * Converts an array to model attributes. 30 | * 31 | * @param array $array The array of attributes. 32 | * @param object|null $object The object to assign attributes to. If null, a new object is created. 33 | * @return object The object with assigned attributes. 34 | */ 35 | protected function arrayToAttributes(array $array, $object = null) 36 | { 37 | // Create a new object if not provided 38 | if (!$object) { 39 | $className = get_called_class(); 40 | $object = new $className; 41 | } 42 | 43 | // Iterate through the array and register attributes to the object 44 | foreach ($array as $attribute => $value) { 45 | // Skip hidden attributes 46 | if ($this->inHiddenAttributes($attribute)) { 47 | continue; 48 | } 49 | $this->registerAttribute($object, $attribute, $value); 50 | } 51 | 52 | return $object; 53 | } 54 | 55 | /** 56 | * Converts an array of arrays to model objects and assigns them to the collection property. 57 | * 58 | * @param array $array The array of arrays containing attributes. 59 | * @return void 60 | */ 61 | protected function arrayToObjects(array $array) 62 | { 63 | $collection = []; 64 | 65 | // Convert each array to a model object and add it to the collection 66 | foreach ($array as $value) { 67 | $object = $this->arrayToAttributes($value); 68 | array_push($collection, $object); 69 | } 70 | 71 | $this->collection = $collection; 72 | } 73 | 74 | /** 75 | * Checks if an attribute is listed in the hidden attributes. 76 | * 77 | * @param string $attribute The name of the attribute. 78 | * @return bool True if the attribute is hidden, false otherwise. 79 | */ 80 | private function inHiddenAttributes($attribute) 81 | { 82 | return in_array($attribute, $this->hidden); 83 | } 84 | 85 | /** 86 | * Checks if an attribute is listed in the casted attributes. 87 | * 88 | * @param string $attribute The name of the attribute. 89 | * @return bool True if the attribute is casted, false otherwise. 90 | */ 91 | private function inCastsAttributes($attribute) 92 | { 93 | return in_array($attribute, array_keys($this->casts)); 94 | } 95 | 96 | /** 97 | * Decodes a casted attribute value based on its type. 98 | * 99 | * @param string $attributeKey The name of the attribute. 100 | * @param mixed $value The value to decode. 101 | * @return mixed The decoded value. 102 | */ 103 | private function castDecodeValue($attributeKey, $value) 104 | { 105 | if ($this->casts[$attributeKey] == 'array' || $this->casts[$attributeKey] == 'object') { 106 | return unserialize($value); 107 | } 108 | 109 | return $value; 110 | } 111 | 112 | /** 113 | * Encodes a value of a casted attribute based on its type. 114 | * 115 | * @param string $attributeKey The name of the attribute. 116 | * @param mixed $value The value to encode. 117 | * @return mixed The encoded value. 118 | */ 119 | private function castEncodeValue($attributeKey, $value) 120 | { 121 | if ($this->casts[$attributeKey] == 'array' || $this->casts[$attributeKey] == 'object') { 122 | return serialize($value); 123 | } 124 | 125 | return $value; 126 | } 127 | 128 | /** 129 | * Encodes an array with casted attribute values. 130 | * 131 | * @param array $values The array of attribute values. 132 | * @return array The encoded array with casted values. 133 | */ 134 | private function arrayToCastEncodeValue($values) 135 | { 136 | $newArray = []; 137 | 138 | // Iterate through the array and encode values with casting if needed 139 | foreach ($values as $attribute => $value) { 140 | $this->inCastsAttributes($attribute) == true ? $newArray[$attribute] = $this->castEncodeValue($attribute, $value) : $newArray[$attribute] = $value; 141 | } 142 | 143 | return $newArray; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /system/Database/Traits/HasCRUD.php: -------------------------------------------------------------------------------- 1 | arrayToCastEncodeValue($values); 24 | $this->arrayToAttributes($values, $this); 25 | // Save the record 26 | return $this->saveMethod(); 27 | } 28 | 29 | /** 30 | * Updates an existing record in the database. 31 | * 32 | * @param array $values An associative array of column names and their corresponding values. 33 | * @return mixed The result of the save method. 34 | */ 35 | protected function updateMethod($values) 36 | { 37 | // Encode values if necessary and set attributes 38 | $values = $this->arrayToCastEncodeValue($values); 39 | $this->arrayToAttributes($values, $this); 40 | // Save the updated record 41 | return $this->saveMethod(); 42 | } 43 | 44 | /** 45 | * Deletes a record from the database. 46 | * 47 | * @param mixed $id The primary key value of the record to delete. 48 | * @return mixed The result of the executeQuery method. 49 | */ 50 | protected function deleteMethod($id = null) 51 | { 52 | // Initialize the object and reset query parameters 53 | $object = $this; 54 | $this->resetQuery(); 55 | // If ID is provided, find the record by ID 56 | if ($id) { 57 | $object = $this->findMethod($id); 58 | $this->resetQuery(); 59 | } 60 | // Construct DELETE query and execute 61 | $object->setSql("DELETE FROM " . $object->getTableName()); 62 | $object->setWhere("AND", $this->getAttributeName($this->primaryKey) . " = ? "); 63 | $object->addValue($object->primaryKey, $object->{$object->primaryKey}); 64 | return $object->executeQuery(); 65 | } 66 | 67 | /** 68 | * Retrieves all records from the database. 69 | * 70 | * @return array The collection of retrieved records. 71 | */ 72 | protected function allMethod() 73 | { 74 | // Construct SELECT query to fetch all records 75 | $this->setSql("SELECT * FROM " . $this->getTableName()); 76 | // Execute query and fetch data 77 | $statement = $this->executeQuery(); 78 | $data = $statement->fetchAll(); 79 | // If data exists, convert to objects and return collection 80 | if ($data) { 81 | $this->arrayToObjects($data); 82 | return $this->collection; 83 | } 84 | // Return an empty array if no records found 85 | return []; 86 | } 87 | 88 | /** 89 | * Finds a record in the database by its primary key. 90 | * 91 | * @param mixed $id The value of the primary key. 92 | * @return mixed|null The found record as an object, or null if not found. 93 | */ 94 | protected function findMethod($id) 95 | { 96 | // Construct SELECT query to find record by ID 97 | $this->setSql("SELECT * FROM " . $this->getTableName()); 98 | $this->setWhere("AND", $this->getAttributeName($this->primaryKey) . " = ? "); 99 | $this->addValue($this->primaryKey, $id); 100 | // Execute query and fetch data 101 | $statement = $this->executeQuery(); 102 | $data = $statement->fetch(); 103 | // Allow subsequent operations on the found record 104 | $this->setAllowedMethods(['update', 'delete', 'save']); 105 | // If data exists, convert to object and return 106 | if ($data) { 107 | return $this->arrayToAttributes($data); 108 | } 109 | // Return null if record not found 110 | return null; 111 | } 112 | 113 | /** 114 | * Adds a WHERE condition to the query with an AND operator. 115 | * 116 | * @param string $attribute The attribute name. 117 | * @param mixed $firstValue The value to compare against. 118 | * @param mixed|null $secondValue Optional. Additional value for comparison. 119 | * @return $this 120 | */ 121 | protected function whereMethod($attribute, $firstValue, $secondValue = null) 122 | { 123 | // Determine the condition based on the number of values provided 124 | if ($secondValue === null) { 125 | $condition = $this->getAttributeName($attribute) . ' = ?'; 126 | $this->addValue($attribute, $firstValue); 127 | } else { 128 | $condition = $this->getAttributeName($attribute) . ' ' . $firstValue . ' ?'; 129 | $this->addValue($attribute, $secondValue); 130 | } 131 | // Set WHERE condition with AND operator 132 | $operator = 'AND'; 133 | $this->setWhere($operator, $condition); 134 | // Allow chaining of other methods 135 | $this->setAllowedMethods(['where', 'whereOr', 'whereIn', 'whereNull', 'whereNotNull', 'limit', 'orderBy', 'get', 'paginate']); 136 | return $this; 137 | } 138 | 139 | /** 140 | * Adds a WHERE condition to the query with an OR operator. 141 | * 142 | * @param string $attribute The attribute name. 143 | * @param mixed $firstValue The value to compare against. 144 | * @param mixed|null $secondValue Optional. Additional value for comparison. 145 | * @return $this 146 | */ 147 | protected function whereOrMethod($attribute, $firstValue, $secondValue = null) 148 | { 149 | // Determine the condition based on the number of values provided 150 | if ($secondValue === null) { 151 | $condition = $this->getAttributeName($attribute) . ' = ?'; 152 | $this->addValue($attribute, $firstValue); 153 | } else { 154 | $condition = $this->getAttributeName($attribute) . ' ' . $firstValue . ' ?'; 155 | $this->addValue($attribute, $secondValue); 156 | } 157 | // Set WHERE condition with OR operator 158 | $operator = 'OR'; 159 | $this->setWhere($operator, $condition); 160 | // Allow chaining of other methods 161 | $this->setAllowedMethods(['where', 'whereOr', 'whereIn', 'whereNull', 'whereNotNull', 'limit', 'orderBy', 'get', 'paginate']); 162 | return $this; 163 | } 164 | 165 | 166 | /** 167 | * Sets a WHERE condition in the query to filter rows where the specified attribute's value is NULL. 168 | * 169 | * @param string $attribute The name of the attribute to check for NULL values. 170 | * @return $this Returns the instance for method chaining. 171 | */ 172 | protected function whereNullMethod($attribute) 173 | { 174 | // Define the condition for NULL values of the attribute 175 | $condition = $this->getAttributeName($attribute) . ' IS NULL '; 176 | 177 | // Set the logical operator for the WHERE clause 178 | $operator = 'AND'; 179 | 180 | // Add the WHERE condition to the query 181 | $this->setWhere($operator, $condition); 182 | 183 | // Set the allowed methods for method chaining 184 | $this->setAllowedMethods(['where', 'whereOr', 'whereIn', 'whereNull', 'whereNotNull', 'limit', 'orderBy', 'get', 'paginate']); 185 | 186 | // Return the instance for method chaining 187 | return $this; 188 | } 189 | 190 | /** 191 | * Sets a WHERE condition in the query to filter rows where the specified attribute's value is NOT NULL. 192 | * 193 | * @param string $attribute The name of the attribute to check for non-NULL values. 194 | * @return $this Returns the instance for method chaining. 195 | */ 196 | protected function whereNotNullMethod($attribute) 197 | { 198 | // Define the condition for non-NULL values of the attribute 199 | $condition = $this->getAttributeName($attribute) . ' IS NOT NULL '; 200 | 201 | // Set the logical operator for the WHERE clause 202 | $operator = 'AND'; 203 | 204 | // Add the WHERE condition to the query 205 | $this->setWhere($operator, $condition); 206 | 207 | // Set the allowed methods for method chaining 208 | $this->setAllowedMethods(['where', 'whereOr', 'whereIn', 'whereNull', 'whereNotNull', 'limit', 'orderBy', 'get', 'paginate']); 209 | 210 | // Return the instance for method chaining 211 | return $this; 212 | } 213 | 214 | /** 215 | * Sets a WHERE condition in the query to filter rows where the specified attribute's value is in a given array. 216 | * 217 | * @param string $attribute The name of the attribute to filter. 218 | * @param array $values The array of values to filter by. 219 | * @return $this Returns the instance for method chaining. 220 | */ 221 | protected function whereInMethod($attribute, $values) 222 | { 223 | // Check if the provided values are in array format 224 | if (is_array($values)) { 225 | $valuesArray = []; 226 | 227 | // Iterate over each value and add it as a parameter 228 | foreach ($values as $value) { 229 | $this->addValue($attribute, $value); 230 | array_push($valuesArray, '?'); 231 | } 232 | 233 | // Construct the condition for the WHERE IN clause 234 | $condition = $this->getAttributeName($attribute) . ' IN (' . implode(' , ', $valuesArray) . ')'; 235 | 236 | // Set the logical operator for the WHERE clause 237 | $operator = 'AND'; 238 | 239 | // Add the WHERE condition to the query 240 | $this->setWhere($operator, $condition); 241 | 242 | // Set the allowed methods for method chaining 243 | $this->setAllowedMethods(['where', 'whereOr', 'whereIn', 'whereNull', 'whereNotNull', 'limit', 'orderBy', 'get', 'paginate']); 244 | 245 | // Return the instance for method chaining 246 | return $this; 247 | } 248 | } 249 | 250 | 251 | /** 252 | * Sets the ORDER BY clause in the query to sort the results by the specified attribute and expression. 253 | * 254 | * @param string $attribute The attribute by which to sort the results. 255 | * @param string $expression The expression to determine the sorting order (ASC or DESC). 256 | * @return $this Returns the instance for method chaining. 257 | */ 258 | protected function orderByMethod($attribute, $expression) 259 | { 260 | // Set the ORDER BY clause with the provided attribute and expression 261 | $this->setOrderBy($attribute, $expression); 262 | 263 | // Set the allowed methods for method chaining 264 | $this->setAllowedMethods(['limit', 'orderBy', 'get', 'paginate']); 265 | 266 | // Return the instance for method chaining 267 | return $this; 268 | } 269 | 270 | /** 271 | * Sets the LIMIT clause in the query to restrict the number of returned rows. 272 | * 273 | * @param int $from The starting index from which to limit the rows. 274 | * @param int $number The maximum number of rows to return. 275 | * @return $this Returns the instance for method chaining. 276 | */ 277 | protected function limitMethod($from, $number) 278 | { 279 | // Set the LIMIT clause with the provided starting index and number of rows 280 | $this->setLimit($from, $number); 281 | 282 | // Set the allowed methods for method chaining 283 | $this->setAllowedMethods(['limit', 'get', 'paginate']); 284 | 285 | // Return the instance for method chaining 286 | return $this; 287 | } 288 | 289 | /** 290 | * Executes the SELECT query with optional specified fields and returns the resulting data. 291 | * 292 | * @param array $array An array of field names to include in the SELECT statement. 293 | * @return array Returns an array containing the retrieved data. 294 | */ 295 | protected function getMethod($array = []) 296 | { 297 | // Check if the SQL query is not already set 298 | if ($this->sql == '') { 299 | // If no specific fields are provided, retrieve all fields 300 | if (empty($array)) { 301 | $fields = $this->getTableName() . '.*'; 302 | } else { 303 | // Otherwise, convert field names to their corresponding attribute names 304 | foreach ($array as $key => $field) { 305 | $array[$key] = $this->getAttributeName($field); 306 | } 307 | $fields = implode(' , ', $array); 308 | } 309 | // Construct the SELECT query with the specified fields 310 | $this->setSql("SELECT $fields FROM " . $this->getTableName()); 311 | } 312 | 313 | // Execute the query and fetch the resulting data 314 | $statement = $this->executeQuery(); 315 | $data = $statement->fetchAll(); 316 | 317 | // If data is retrieved, convert it to objects and return as a collection 318 | if ($data) { 319 | $this->arrayToObjects($data); 320 | return $this->collection; 321 | } 322 | 323 | // Return an empty array if no data is retrieved 324 | return []; 325 | } 326 | 327 | 328 | 329 | /** 330 | * Paginates the results of the query based on the specified number of items per page. 331 | * 332 | * @param int $perPage The number of items to display per page. 333 | * @return array Returns an array containing the paginated data. 334 | */ 335 | protected function paginateMethod($perPage) 336 | { 337 | // Calculate the total number of rows 338 | $totalRows = $this->getCount(); 339 | 340 | // Determine the current page number 341 | $currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1; 342 | 343 | // Calculate the total number of pages 344 | $totalPages = ceil($totalRows / $perPage); 345 | 346 | // Ensure the current page is within the valid range 347 | $currentPage = min($currentPage, $totalPages); 348 | $currentPage = max($currentPage, 1); 349 | 350 | // Calculate the starting row for the current page 351 | $currentRow = ($currentPage - 1) * $perPage; 352 | 353 | // Set the LIMIT clause to fetch the data for the current page 354 | $this->setLimit($currentRow, $perPage); 355 | 356 | // If SQL query is not already set, construct the SELECT query 357 | if ($this->sql == '') { 358 | $this->setSql("SELECT " . $this->getTableName() . ".* FROM " . $this->getTableName()); 359 | } 360 | 361 | // Execute the query and fetch the resulting data 362 | $statement = $this->executeQuery(); 363 | $data = $statement->fetchAll(); 364 | 365 | // If data is retrieved, convert it to objects and return as a collection 366 | if ($data) { 367 | $this->arrayToObjects($data); 368 | return $this->collection; 369 | } 370 | 371 | // Return an empty array if no data is retrieved 372 | return []; 373 | } 374 | 375 | /** 376 | * Saves the current object to the database, either by inserting a new record or updating an existing one. 377 | * 378 | * @return $this Returns the instance for method chaining. 379 | */ 380 | protected function saveMethod() 381 | { 382 | // Generate the fill string for INSERT or UPDATE query 383 | $fillString = $this->fill(); 384 | 385 | // Check if the primary key is set to determine if it's an INSERT or UPDATE operation 386 | if (!isset($this->{$this->primaryKey})) { 387 | // Construct the INSERT query with the fill string and current timestamp for 'createdAt' attribute 388 | $this->setSql("INSERT INTO " . $this->getTableName() . " SET $fillString, " . $this->getAttributeName($this->createdAt) . "=Now()"); 389 | } else { 390 | // Construct the UPDATE query with the fill string and current timestamp for 'updatedAt' attribute 391 | $this->setSql("UPDATE " . $this->getTableName() . " SET $fillString, " . $this->getAttributeName($this->updatedAt) . "=Now()"); 392 | 393 | // Set the WHERE clause for the primary key 394 | $this->setWhere("AND", $this->getAttributeName($this->primaryKey) . " = ?"); 395 | $this->addValue($this->primaryKey, $this->{$this->primaryKey}); 396 | } 397 | 398 | // Execute the query 399 | $this->executeQuery(); 400 | 401 | // Reset the query builder 402 | $this->resetQuery(); 403 | 404 | // If it's an INSERT operation, fetch the inserted object from the database 405 | if (!isset($this->{$this->primaryKey})) { 406 | $object = $this->findMethod(DBConnection::newInsertId()); 407 | $defaultVars = get_class_vars(get_called_class()); 408 | $allVars = get_object_vars($object); 409 | $differentVars = array_diff(array_keys($allVars), array_keys($defaultVars)); 410 | foreach ($differentVars as $attribute) { 411 | // Register attributes with their values in the current object 412 | $this->inCastsAttributes($attribute) == true ? $this->registerAttribute($this, $attribute, $this->castEncodeValue($attribute, $object->$attribute)) : $this->registerAttribute($this, $attribute, $object->$attribute); 413 | } 414 | } 415 | 416 | // Reset the query builder 417 | $this->resetQuery(); 418 | 419 | // Set the allowed methods for method chaining 420 | $this->setAllowedMethods(['update', 'delete', 'find']); 421 | 422 | // Return the instance for method chaining 423 | return $this; 424 | } 425 | 426 | /** 427 | * Generates the fill string for INSERT or UPDATE query based on the fillable attributes. 428 | * 429 | * @return string Returns the fill string for the query. 430 | */ 431 | protected function fill() 432 | { 433 | // Initialize an empty array to store fill attributes and values 434 | $fillArray = array(); 435 | 436 | // Iterate through fillable attributes and add them to the fill array 437 | foreach ($this->fillable as $attribute) { 438 | if (isset($this->$attribute)) { 439 | // Add attribute and placeholder to the fill array 440 | array_push($fillArray, $this->getAttributeName($attribute) . " = ?"); 441 | 442 | // Determine whether to cast the attribute value before adding to the query 443 | $this->inCastsAttributes($attribute) == true ? $this->addValue($attribute, $this->castEncodeValue($attribute, $this->$attribute)) : $this->addValue($attribute, $this->$attribute); 444 | } 445 | } 446 | 447 | // Generate the fill string by imploding the fill array with commas 448 | $fillString = implode(', ', $fillArray); 449 | 450 | // Return the fill string 451 | return $fillString; 452 | } 453 | } 454 | -------------------------------------------------------------------------------- /system/Database/Traits/HasMethodCaller.php: -------------------------------------------------------------------------------- 1 | methodCaller($this, $method, $args); 26 | } 27 | 28 | /** 29 | * Magic method to handle dynamic method calls in a static context. 30 | * 31 | * @param string $method The name of the method being called. 32 | * @param array $args An array of arguments passed to the method. 33 | * @return mixed Returns the result of the method call. 34 | */ 35 | public static function __callStatic($method, $args) 36 | { 37 | // Get the name of the calling class 38 | $className = get_called_class(); 39 | 40 | // Create a new instance of the calling class 41 | $instance = new $className; 42 | 43 | // Call the methodCaller function with the instance, method name, and arguments 44 | return $instance->methodCaller($instance, $method, $args); 45 | } 46 | 47 | /** 48 | * Calls the specified method on the object with the provided arguments. 49 | * 50 | * @param object $object The object on which the method is being called. 51 | * @param string $method The name of the method being called. 52 | * @param array $args An array of arguments passed to the method. 53 | * @return mixed Returns the result of the method call. 54 | */ 55 | private function methodCaller($object, $method, $args) 56 | { 57 | // Append the suffix 'Method' to the method name 58 | $suffix = 'Method'; 59 | $methodName = $method . $suffix; 60 | 61 | // Check if the method is allowed for calling 62 | if (in_array($method, $this->allowedMethods)) { 63 | // Call the specified method on the object with the provided arguments 64 | return call_user_func_array(array($object, $methodName), $args); 65 | } 66 | } 67 | 68 | /** 69 | * Sets the allowed methods for method calling. 70 | * 71 | * @param array $array An array containing the names of allowed methods. 72 | * @return void 73 | */ 74 | protected function setAllowedMethods($array) 75 | { 76 | $this->allowedMethods = $array; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /system/Database/Traits/HasQueryBuilder.php: -------------------------------------------------------------------------------- 1 | sql = $query; 39 | } 40 | 41 | /** 42 | * Gets the current SQL query string. 43 | * 44 | * @return string The current SQL query string. 45 | */ 46 | protected function getSql() 47 | { 48 | return $this->sql; 49 | } 50 | 51 | 52 | /** 53 | * The resetSql method resets the SQL query string. 54 | * 55 | * @return void 56 | */ 57 | protected function resetSql() 58 | { 59 | $this->sql = ''; 60 | } 61 | 62 | /** 63 | * The setWhere method sets a WHERE condition in the query. 64 | * 65 | * @param string $operator The operator to be used in the WHERE condition. 66 | * @param string $condition The condition to be applied in the WHERE clause. 67 | * @return void 68 | */ 69 | protected function setWhere($operator, $condition) 70 | { 71 | // Construct an associative array representing the WHERE condition 72 | $array = ['operator' => $operator, 'condition' => $condition]; 73 | // Push the WHERE condition into the $where property 74 | array_push($this->where, $array); 75 | } 76 | 77 | /** 78 | * The resetWhere method resets the WHERE conditions in the query. 79 | * 80 | * @return void 81 | */ 82 | protected function resetWhere() 83 | { 84 | // Reset the $where property to an empty array 85 | $this->where = []; 86 | } 87 | 88 | /** 89 | * The setOrderBy method sets an ORDER BY clause in the query. 90 | * 91 | * @param string $name The name of the attribute to be ordered. 92 | * @param string $expression The expression for ordering (ASC or DESC). 93 | * @return void 94 | */ 95 | protected function setOrderBy($name, $expression) 96 | { 97 | // Construct the ORDER BY clause and push it into the $orderBy property 98 | array_push($this->orderBy, $this->getAttributeName($name) . ' ' . $expression); 99 | } 100 | 101 | /** 102 | * The resetOrderBy method resets the ORDER BY clauses in the query. 103 | * 104 | * @return void 105 | */ 106 | protected function resetOrderBy() 107 | { 108 | // Reset the $orderBy property to an empty array 109 | $this->orderBy = []; 110 | } 111 | 112 | /** 113 | * The setLimit method sets the LIMIT clause in the SQL query. 114 | * 115 | * @param int $from The starting offset of the LIMIT. 116 | * @param int $number The maximum number of rows to return. 117 | * @return void 118 | */ 119 | protected function setLimit($from, $number) 120 | { 121 | // Set the starting offset and the number of rows to return in the LIMIT clause 122 | $this->limit['from'] = (int) $from; 123 | $this->limit['number'] = (int) $number; 124 | } 125 | 126 | /** 127 | * The resetLimit method resets the LIMIT clause in the SQL query. 128 | * 129 | * @return void 130 | */ 131 | protected function resetLimit() 132 | { 133 | // Unset the 'from' and 'number' keys in the $limit property 134 | unset($this->limit['from']); 135 | unset($this->limit['number']); 136 | } 137 | 138 | /** 139 | * The addValue method adds a parameter value for prepared statements. 140 | * 141 | * @param string $attribute The attribute name. 142 | * @param mixed $value The value to be bound. 143 | * @return void 144 | */ 145 | protected function addValue($attribute, $value) 146 | { 147 | // Set the parameter value in the $values property 148 | $this->values[$attribute] = $value; 149 | // Add the parameter value to the array of bound values 150 | array_push($this->bindValues, $value); 151 | } 152 | 153 | /** 154 | * The removeValues method clears the stored parameter values. 155 | * 156 | * @return void 157 | */ 158 | protected function removeValues() 159 | { 160 | // Reset the $values and $bindValues properties to empty arrays 161 | $this->values = []; 162 | $this->bindValues = []; 163 | } 164 | 165 | /** 166 | * The resetQuery method resets all query-related properties. 167 | * 168 | * @return void 169 | */ 170 | protected function resetQuery() 171 | { 172 | // Reset all query-related properties 173 | $this->resetSql(); 174 | $this->resetWhere(); 175 | $this->resetOrderBy(); 176 | $this->resetLimit(); 177 | $this->removeValues(); 178 | } 179 | 180 | /** 181 | * The executeQuery method executes the constructed SQL query. 182 | * 183 | * @return PDOStatement The PDOStatement object representing the result of the query. 184 | */ 185 | protected function executeQuery() 186 | { 187 | // Construct the SQL query string 188 | $query = $this->sql; 189 | 190 | // Append WHERE conditions to the query string if present 191 | if (!empty($this->where)) { 192 | $whereString = ''; 193 | foreach ($this->where as $where) { 194 | $whereString == '' ? $whereString .= $where['condition'] : $whereString .= ' ' . $where['operator'] . ' ' . $where['condition']; 195 | } 196 | $query .= ' WHERE ' . $whereString; 197 | } 198 | 199 | // Append ORDER BY clauses to the query string if present 200 | if (!empty($this->orderBy)) { 201 | $query .= ' ORDER BY ' . implode(', ', $this->orderBy); 202 | } 203 | 204 | // Append LIMIT clause to the query string if present 205 | if (!empty($this->limit)) { 206 | $query .= ' LIMIT ' . $this->limit['from'] . ', ' . $this->limit['number']; 207 | } 208 | 209 | // Prepare and execute the SQL query using the PDO instance 210 | $pdoInstance = DBConnection::getDBConnectionInstance(); 211 | $statement = $pdoInstance->prepare($query); 212 | if (sizeof($this->bindValues) > sizeof($this->values)) { 213 | sizeof($this->bindValues) > 0 ? $statement->execute($this->bindValues) : $statement->execute(); 214 | } else { 215 | sizeof($this->values) > 0 ? $statement->execute(array_values($this->values)) : $statement->execute(); 216 | } 217 | 218 | // Return the PDOStatement object representing the result of the query 219 | return $statement; 220 | } 221 | 222 | 223 | 224 | /** 225 | * The getCount method retrieves the total number of rows that match the current query conditions. 226 | * 227 | * @return int The total number of rows. 228 | */ 229 | protected function getCount() 230 | { 231 | // Initialize an empty query string 232 | $query = ''; 233 | 234 | // Construct the SELECT COUNT(*) query to count the rows 235 | $query .= "SELECT COUNT(*) FROM " . $this->getTableName(); 236 | 237 | // Append WHERE conditions to the query string if present 238 | if (!empty($this->where)) { 239 | $whereString = ''; 240 | foreach ($this->where as $where) { 241 | $whereString == '' ? $whereString .= $where['condition'] : $whereString .= ' ' . $where['operator'] . ' ' . $where['condition']; 242 | } 243 | $query .= ' WHERE ' . $whereString; 244 | } 245 | 246 | // Append semicolon to the query string 247 | $query .= ' ;'; 248 | 249 | // Retrieve the PDO instance 250 | $pdoInstance = DBConnection::getDBConnectionInstance(); 251 | 252 | // Prepare and execute the SQL query using the PDO instance 253 | $statement = $pdoInstance->prepare($query); 254 | if (sizeof($this->bindValues) > sizeof($this->values)) { 255 | sizeof($this->bindValues) > 0 ? $statement->execute($this->bindValues) : $statement->execute(); 256 | } else { 257 | sizeof($this->values) > 0 ? $statement->execute(array_values($this->values)) : $statement->execute(); 258 | } 259 | 260 | // Fetch and return the total number of rows as a single column 261 | return $statement->fetchColumn(); 262 | } 263 | 264 | /** 265 | * The getTableName method returns the formatted table name for use in SQL queries. 266 | * 267 | * @return string The formatted table name. 268 | */ 269 | protected function getTableName() 270 | { 271 | // Format and return the table name with backticks for SQL queries 272 | return ' `' . $this->table . '`'; 273 | } 274 | 275 | /** 276 | * The getAttributeName method returns the formatted attribute name for use in SQL queries. 277 | * 278 | * @param string $attribute The attribute name. 279 | * @return string The formatted attribute name. 280 | */ 281 | protected function getAttributeName($attribute) 282 | { 283 | // Format and return the attribute name with table name and backticks for SQL queries 284 | return ' `' . $this->table . '`.`' . $attribute . '` '; 285 | } 286 | } 287 | -------------------------------------------------------------------------------- /system/Database/Traits/HasRelation.php: -------------------------------------------------------------------------------- 1 | {$this->primaryKey}) { 19 | // Create an instance of the related model 20 | $modelObject = new $model(); 21 | // Retrieve and return the one-to-one relationship 22 | return $modelObject->getHasOneRelation($this->table, $foreignKey, $localKey, $this->$localKey); 23 | } 24 | } 25 | 26 | /** 27 | * The getHasOneRelation method retrieves the related model in a one-to-one relationship. 28 | * 29 | * @param string $table The name of the related model's table. 30 | * @param string $foreignKey The foreign key in the related model's table. 31 | * @param string $otherKey The key in the related model's table. 32 | * @param mixed $otherKeyValue The value of the key in the related model. 33 | * @return mixed|null The related model object if found, otherwise null. 34 | */ 35 | public function getHasOneRelation($table, $foreignKey, $otherKey, $otherKeyValue) 36 | { 37 | // Construct the SQL query for retrieving the related model in a one-to-one relationship 38 | $this->setSql("SELECT `b`.* FROM `{$table}` AS `a` JOIN " . $this->getTableName() . " AS `b` on `a`.`{$otherKey}` = `b`.`{$foreignKey}` "); 39 | $this->setWhere('AND', "`a`.`$otherKey` = ? "); 40 | $this->table = 'b'; 41 | $this->addValue($otherKey, $otherKeyValue); 42 | // Execute the query and fetch the data 43 | $statement = $this->executeQuery(); 44 | $data = $statement->fetch(); 45 | // If data is found, convert it to model attributes and return, otherwise return null 46 | if ($data) 47 | return $this->arrayToAttributes($data); 48 | return null; 49 | } 50 | 51 | /** 52 | * The hasMany method establishes a one-to-many relationship with another model. 53 | * 54 | * @param string $model The name of the related model class. 55 | * @param string $foreignKey The foreign key in the related model's table. 56 | * @param string $otherKey The key in the related model's table. 57 | * @return mixed|null The related model object if found, otherwise null. 58 | */ 59 | protected function hasMany($model, $foreignKey, $otherKey) 60 | { 61 | // Check if the current model has a primary key value 62 | if ($this->{$this->primaryKey}) { 63 | // Create an instance of the related model 64 | $modelObject = new $model; 65 | // Retrieve and return the one-to-many relationship 66 | return $modelObject->getHasManyRelation($this->table, $foreignKey, $otherKey, $this->$otherKey); 67 | } 68 | } 69 | 70 | /** 71 | * The getHasManyRelation method retrieves the related models in a one-to-many relationship. 72 | * 73 | * @param string $table The name of the related model's table. 74 | * @param string $foreignKey The foreign key in the related model's table. 75 | * @param string $otherKey The key in the related model's table. 76 | * @param mixed $otherKeyValue The value of the key in the related model. 77 | * @return mixed|null The related model object if found, otherwise null. 78 | */ 79 | public function getHasManyRelation($table, $foreignKey, $otherKey, $otherKeyValue) 80 | { 81 | // Construct the SQL query for retrieving the related models in a one-to-many relationship 82 | $this->setSql("SELECT `b`.* FROM `{$table}` AS `a` JOIN " . $this->getTableName() . " AS `b` on `a`.`{$otherKey}` = `b`.`{$foreignKey}` "); 83 | $this->setWhere('AND', "`a`.`$otherKey` = ? "); 84 | $this->table = 'b'; 85 | $this->addValue($otherKey, $otherKeyValue); 86 | // Return the current instance to allow chaining of methods 87 | return $this; 88 | } 89 | 90 | 91 | /** 92 | * The belongsTo method establishes a many-to-one relationship with another model. 93 | * 94 | * @param string $model The name of the related model class. 95 | * @param string $foreignKey The foreign key in the current model's table. 96 | * @param string $localKey The local key in the related model's table. 97 | * @return mixed|null The related model object if found, otherwise null. 98 | */ 99 | protected function belongsTo($model, $foreignKey, $localKey) 100 | { 101 | // Check if the current model has a primary key value 102 | if ($this->{$this->primaryKey}) { 103 | // Create an instance of the related model 104 | $modelObject = new $model(); 105 | // Retrieve and return the many-to-one relationship 106 | return $modelObject->getBelongsToRelation($this->table, $foreignKey, $localKey, $this->$foreignKey); 107 | } 108 | } 109 | 110 | /** 111 | * The getBelongsToRelation method retrieves the related model in a many-to-one relationship. 112 | * 113 | * @param string $table The name of the related model's table. 114 | * @param string $foreignKey The foreign key in the current model's table. 115 | * @param string $otherKey The key in the related model's table. 116 | * @param mixed $foreignKeyValue The value of the foreign key in the current model. 117 | * @return mixed|null The related model object if found, otherwise null. 118 | */ 119 | public function getBelongsToRelation($table, $foreignKey, $otherKey, $foreignKeyValue) 120 | { 121 | // Construct the SQL query for retrieving the related model in a many-to-one relationship 122 | $this->setSql("SELECT `b`.* FROM `{$table}` AS `a` JOIN " . $this->getTableName() . " AS `b` on `a`.`{$foreignKey}` = `b`.`{$otherKey}` "); 123 | $this->setWhere('AND', "`a`.`$foreignKey` = ? "); 124 | $this->table = 'b'; 125 | $this->addValue($foreignKey, $foreignKeyValue); 126 | // Execute the query and fetch the data 127 | $statement = $this->executeQuery(); 128 | $data = $statement->fetch(); 129 | // If data is found, convert it to model attributes and return, otherwise return null 130 | if ($data) 131 | return $this->arrayToAttributes($data); 132 | return null; 133 | } 134 | 135 | /** 136 | * The belongsToMany method establishes a many-to-many relationship with another model through an intermediate table. 137 | * 138 | * @param string $model The name of the related model class. 139 | * @param string $commonTable The name of the intermediate table. 140 | * @param string $localKey The local key in the current model's table. 141 | * @param string $middleForeignKey The foreign key in the intermediate table pointing to the current model. 142 | * @param string $middleRelation The key in the intermediate table. 143 | * @param string $foreignKey The foreign key in the related model's table. 144 | * @return mixed|null The related model object if found, otherwise null. 145 | */ 146 | protected function belongsToMany($model, $commonTable, $localKey, $middleForeignKey, $middleRelation, $foreignKey) 147 | { 148 | // Check if the current model has a primary key value 149 | if ($this->{$this->primaryKey}) { 150 | // Create an instance of the related model 151 | $modelObject = new $model(); 152 | // Retrieve and return the many-to-many relationship 153 | return $modelObject->getBelongsToManyRelation($this->table, $commonTable, $localKey, $this->$localKey, $middleForeignKey, $middleRelation, $foreignKey); 154 | } 155 | } 156 | 157 | /** 158 | * The getBelongsToManyRelation method retrieves the related models in a many-to-many relationship through an intermediate table. 159 | * 160 | * @param string $table The name of the related model's table. 161 | * @param string $commonTable The name of the intermediate table. 162 | * @param string $localKey The local key in the current model's table. 163 | * @param mixed $localKeyValue The value of the local key in the current model. 164 | * @param string $middleForeignKey The foreign key in the intermediate table pointing to the current model. 165 | * @param string $middleRelation The key in the intermediate table. 166 | * @param string $foreignKey The foreign key in the related model's table. 167 | * @return mixed|null The related model object if found, otherwise null. 168 | */ 169 | protected function getBelongsToManyRelation($table, $commonTable, $localKey, $localKeyValue, $middleForeignKey, $middleRelation, $foreignKey) 170 | { 171 | // Construct the SQL query for retrieving the related models in a many-to-many relationship through an intermediate table 172 | $this->setSql("SELECT `c`.* FROM ( SELECT `b`.* FROM `{$table}` AS `a` JOIN `{$commonTable}` AS `b` on `a`.`{$localKey}` = `b`.`{$middleForeignKey}` WHERE `a`.`{$localKey}` = ? ) AS `relation` JOIN " . $this->getTableName() . " AS `c` ON `relation`.`{$middleRelation}` = `c`.`$foreignKey`"); 173 | $this->addValue("{$table}_{$localKey}", $localKeyValue); 174 | $this->table = 'c'; 175 | // Return the current instance to allow chaining of methods 176 | return $this; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /system/Database/Traits/HasSoftDelete.php: -------------------------------------------------------------------------------- 1 | resetQuery(); // Resetting the query builder. 18 | $object = $this->findMethod($id); // Finding the object by ID. 19 | } 20 | if ($object) { 21 | $object->resetQuery(); // Resetting the query builder for the object. 22 | $object->setSql("UPDATE " . $object->getTableName() . " SET " . $this->getAttributeName($this->deletedAt) . " = NOW() "); // Setting SQL to update the deletion timestamp. 23 | $object->setWhere("AND", $this->getAttributeName($object->primaryKey) . " = ?"); // Adding WHERE condition for the primary key. 24 | $object->addValue($object->primaryKey, $object->{$object->primaryKey}); // Binding the primary key value. 25 | return $object->executeQuery(); // Executing the update query. 26 | } 27 | } 28 | 29 | /** 30 | * Method to fetch all records that are not soft deleted. 31 | * 32 | * @return array Array of objects representing the fetched records. 33 | */ 34 | protected function allMethod() 35 | { 36 | $this->setSql("SELECT " . $this->getTableName() . ".* FROM " . $this->getTableName()); // Setting SQL for fetching all records. 37 | $this->setWhere("AND", $this->getAttributeName($this->deletedAt) . " IS NULL "); // Adding WHERE condition to exclude soft deleted records. 38 | $statement = $this->executeQuery(); // Executing the query. 39 | $data = $statement->fetchAll(); // Fetching data from the statement. 40 | if ($data) { 41 | $this->arrayToObjects($data); // Converting fetched data to objects. 42 | return $this->collection; // Returning the collection of objects. 43 | } 44 | return []; // Returning an empty array if no records found. 45 | } 46 | 47 | /** 48 | * Method to find a record by ID that is not soft deleted. 49 | * 50 | * @param int $id The ID of the record to find. 51 | * @return object|null The found object or null if not found or soft deleted. 52 | */ 53 | protected function findMethod($id) 54 | { 55 | $this->resetQuery(); // Resetting the query builder. 56 | $this->setSql("SELECT " . $this->getTableName() . ".* FROM " . $this->getTableName()); // Setting SQL for fetching the record. 57 | $this->setWhere("AND", $this->getAttributeName($this->primaryKey) . " = ? "); // Adding WHERE condition for the primary key. 58 | $this->addValue($this->primaryKey, $id); // Binding the primary key value. 59 | $this->setWhere("AND", $this->getAttributeName($this->deletedAt) . " IS NULL "); // Adding WHERE condition to exclude soft deleted records. 60 | $statement = $this->executeQuery(); // Executing the query. 61 | $data = $statement->fetch(); // Fetching data from the statement. 62 | $this->setAllowedMethods(['update', 'delete', 'save']); // Setting allowed methods for the object. 63 | if ($data) 64 | return $this->arrayToAttributes($data); // Converting fetched data to object attributes. 65 | return null; // Returning null if record not found or soft deleted. 66 | } 67 | 68 | /** 69 | * Method to get records based on provided conditions that are not soft deleted. 70 | * 71 | * @param array $array Array of field names to fetch. 72 | * @return array Array of objects representing the fetched records. 73 | */ 74 | protected function getMethod($array = []) 75 | { 76 | if ($this->sql == '') { 77 | if (empty($array)) { 78 | $fields = $this->getTableName() . '.*'; // If no specific fields are provided, fetch all fields. 79 | } else { 80 | foreach ($array as $key => $field) { 81 | $array[$key] = $this->getAttributeName($field); // Converting field names to their attribute names. 82 | } 83 | $fields = implode(' , ', $array); // Joining field names with commas. 84 | } 85 | $this->setSql("SELECT $fields FROM " . $this->getTableName()); // Setting SQL for fetching records. 86 | } 87 | $this->setWhere("AND", $this->getAttributeName($this->deletedAt) . " IS NULL "); // Adding WHERE condition to exclude soft deleted records. 88 | $statement = $this->executeQuery(); // Executing the query. 89 | $data = $statement->fetchAll(); // Fetching data from the statement. 90 | if ($data) { 91 | $this->arrayToObjects($data); // Converting fetched data to objects. 92 | return $this->collection; // Returning the collection of objects. 93 | } 94 | return []; // Returning an empty array if no records found. 95 | } 96 | 97 | /** 98 | * Method to paginate records that are not soft deleted. 99 | * 100 | * @param int $perPage Number of records per page. 101 | * @return array Array of objects representing the fetched records for the current page. 102 | */ 103 | protected function paginateMethod($perPage) 104 | { 105 | $this->setWhere("AND", $this->getAttributeName($this->deletedAt) . " IS NULL "); // Adding WHERE condition to exclude soft deleted records. 106 | $totalRows = $this->getCount(); // Getting the total count of records. 107 | $currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1; // Getting the current page number from the query parameters. 108 | $totalPages = ceil($totalRows / $perPage); // Calculating the total number of pages. 109 | $currentPage = min($currentPage, $totalPages); // Making sure current page is not greater than total pages. 110 | $currentPage = max($currentPage, 1); // Making sure current page is not less than 1. 111 | $currentRow = ($currentPage - 1) * $perPage; // Calculating the starting row for the current page. 112 | $this->setLimit($currentRow, $perPage); // Setting limit for pagination. 113 | if ($this->sql == '') { 114 | $this->setSql("SELECT " . $this->getTableName() . ".* FROM " . $this->getTableName()); // Setting SQL for fetching records. 115 | } 116 | $statement = $this->executeQuery(); // Executing the query. 117 | $data = $statement->fetchAll(); // Fetching data from the statement. 118 | if ($data) { 119 | $this->arrayToObjects($data); // Converting fetched data to objects. 120 | return $this->collection; // Returning the collection of objects. 121 | } 122 | return []; // Returning an empty array if no records found. 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /system/Helpers/coreHelper.php: -------------------------------------------------------------------------------- 1 | tags 57 | * for better readability, and then exits the script. 58 | * 59 | * @param mixed $var The variable to dump 60 | */ 61 | function dd($var) 62 | { 63 | // Dump the variable and exit 64 | echo '
';
 65 |     var_dump($var);
 66 |     exit;
 67 | }
 68 | 
 69 | /**
 70 |  * Retrieves the value of an environment variable.
 71 |  *
 72 |  * This function retrieves the value of the specified environment variable.
 73 |  *
 74 |  * @param string $name The name of the environment variable
 75 |  * @return mixed The value of the environment variable
 76 |  */
 77 | function env($name)
 78 | {
 79 |     return $_ENV[$name];
 80 | }
 81 | 
 82 | /**
 83 |  * Converts Persian and Arabic numerals in a string to English numerals.
 84 |  *
 85 |  * This function replaces Persian and Arabic numerals in the input string
 86 |  * with their corresponding English numerals (0-9).
 87 |  *
 88 |  * @param string $string The string containing Persian or Arabic numerals
 89 |  * @return string The string with Persian and Arabic numerals converted to English
 90 |  */
 91 | function persianNumbersToEnglish($string)
 92 | {
 93 |     // Arrays of Persian and Arabic numerals
 94 |     $persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
 95 |     $arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
 96 | 
 97 |     // English numerals (0-9)
 98 |     $num = range(0, 9);
 99 | 
100 |     // Replace Persian numerals with English numerals
101 |     $convertedPersianNums = str_replace($persian, $num, $string);
102 | 
103 |     // Replace Arabic numerals with English numerals
104 |     $englishNumbersOnly = str_replace($arabic, $num, $convertedPersianNums);
105 | 
106 |     return $englishNumbersOnly;
107 | }
108 | 


--------------------------------------------------------------------------------
/system/Kernel/Traits/HasAttribute.php:
--------------------------------------------------------------------------------
  1 | update.
166 |         $this->setUpdate($content);
167 | 
168 |         // Set the chat ID where the message originated.
169 |         $this->setChatId();
170 | 
171 |         // Set the message text content, converting Persian numbers if necessary.
172 |         $this->setText();
173 | 
174 |         // Set the unique message ID.
175 |         $this->setMessageId();
176 | 
177 |         // If message sender's information is available, extract and store their details.
178 |         if (isset($this->update['message']['from'])) {
179 |             $this->setFirstName();
180 |             $this->setLastName();
181 |             $this->setUserName();
182 |         }
183 | 
184 |         // Extract media file IDs if available, such as video, audio, document, or photo.
185 |         if (isset($this->update['message']['video'])) $this->setVideoId();
186 |         if (isset($this->update['message']['audio'])) $this->setAudioId();
187 |         if (isset($this->update['message']['document'])) $this->setDocumentId();
188 |         if (isset($this->update['message']['photo'][0]['file_id'])) $this->setPhotoId();
189 | 
190 |         // If a caption is present, store it.
191 |         if (isset($this->update['message']['caption'])) $this->setCaption();
192 | 
193 |         // If the update includes callback data (from an inline keyboard), extract and store callback information.
194 |         if (isset($this->update['callback_query']['data'])) {
195 |             $this->setCallback();
196 |             $this->setFirstName("callback_query");
197 |             $this->setLastName("callback_query");
198 |             $this->setUserName("callback_query");
199 |             $this->setChatId("callback_query");
200 |             $this->setCallbackQueryId();
201 |             $this->setType();
202 |             $this->setUpdateId();
203 |             $this->setContent();
204 |         }
205 |     }
206 | 
207 |     // Individual setter methods for each attribute with comments explaining each step.
208 | 
209 |     /**
210 |      * Sets the callback data.
211 |      */
212 |     public function setCallback()
213 |     {
214 |         $this->callback = $this->update['callback_query']['data']; // Retrieves and stores the callback data.
215 |     }
216 | 
217 |     /**
218 |      * Sets the callback query ID.
219 |      */
220 |     public function setCallbackQueryId()
221 |     {
222 |         $this->callback_query_id = $this->update['callback_query']['id']; // Retrieves and stores the callback query ID.
223 |     }
224 | 
225 |     /**
226 |      * Sets the type of chat (e.g., private, group) for the callback.
227 |      */
228 |     public function setType()
229 |     {
230 |         $this->type = $this->update['callback_query']['message']['chat']['type']; // Retrieves and stores the chat type.
231 |     }
232 | 
233 |     /**
234 |      * Sets the update ID.
235 |      */
236 |     public function setUpdateId()
237 |     {
238 |         $this->update_id = $this->update['callback_query']['message']['message_id']; // Retrieves and stores the update ID.
239 |     }
240 | 
241 |     /**
242 |      * Sets the content of a callback message.
243 |      */
244 |     public function setContent()
245 |     {
246 |         $this->content = $this->update['callback_query']['message']['text']; // Retrieves and stores callback message content.
247 |     }
248 | 
249 |     /**
250 |      * Sets the caption of the message, if available.
251 |      */
252 |     public function setCaption()
253 |     {
254 |         $this->caption = $this->update['message']['caption']; // Retrieves and stores caption text if present.
255 |     }
256 | 
257 |     /**
258 |      * Sets the photo ID, if a photo is attached.
259 |      */
260 |     public function setPhotoId()
261 |     {
262 |         $this->photo_id = end($this->update['message']['photo'])['file_id']; // Retrieves and stores the last photo file ID.
263 |     }
264 | 
265 |     /**
266 |      * Sets the document ID, if a document is attached.
267 |      */
268 |     public function setDocumentId()
269 |     {
270 |         $this->document_id = $this->update['message']['document']['file_id']; // Retrieves and stores the document file ID.
271 |     }
272 | 
273 |     /**
274 |      * Sets the audio ID, if an audio file is attached.
275 |      */
276 |     public function setAudioId()
277 |     {
278 |         $this->audio_id = $this->update['message']['audio']['file_id']; // Retrieves and stores the audio file ID.
279 |     }
280 | 
281 |     /**
282 |      * Sets the video ID, if a video is attached.
283 |      */
284 |     public function setVideoId()
285 |     {
286 |         $this->video_id = $this->update['message']['video']['file_id']; // Retrieves and stores the video file ID.
287 |     }
288 | 
289 |     /**
290 |      * Sets the username of the sender.
291 |      *
292 |      * @param string $type If "callback_query", sets username for callback.
293 |      */
294 |     public function setUserName($type = "normal")
295 |     {
296 |         $this->username = ($type === "normal") ?
297 |             ($this->update['message']['from']['username'] ?? '') : // Checks if username exists for message.
298 |             $this->update['callback_query']['from']['username'];    // Uses username for callback query if applicable.
299 |     }
300 | 
301 |     /**
302 |      * Sets the last name of the sender.
303 |      *
304 |      * @param string $type If "callback_query", sets last name for callback.
305 |      */
306 |     public function setLastName($type = "normal")
307 |     {
308 |         $this->last_name = ($type === "normal") ?
309 |             ($this->update['message']['from']['last_name'] ?? '') : // Checks if last name exists for message.
310 |             $this->update['callback_query']['from']['last_name'];   // Uses last name for callback query if applicable.
311 |     }
312 | 
313 |     /**
314 |      * Sets the first name of the sender.
315 |      *
316 |      * @param string $type If "callback_query", sets first name for callback.
317 |      */
318 |     public function setFirstName($type = "normal")
319 |     {
320 |         $this->first_name = ($type === "normal") ?
321 |             ($this->update['message']['from']['first_name'] ?? '') : // Checks if first name exists for message.
322 |             $this->update['callback_query']['from']['first_name'];   // Uses first name for callback query if applicable.
323 |     }
324 | 
325 |     /**
326 |      * Decodes the incoming JSON content and stores it as an array.
327 |      *
328 |      * @param string $content JSON string containing the Telegram update.
329 |      */
330 |     public function setUpdate($content)
331 |     {
332 |         $this->update = json_decode($content, true); // Decodes JSON content to associative array.
333 |     }
334 | 
335 |     /**
336 |      * Sets the unique message ID from the update.
337 |      */
338 |     public function setMessageId()
339 |     {
340 |         $this->messageID = $this->update['message']['message_id']; // Retrieves and stores the message ID.
341 |     }
342 | 
343 |     /**
344 |      * Sets the text content of the message, converting any Persian numbers to English.
345 |      */
346 |     public function setText()
347 |     {
348 |         $this->text = persianNumbersToEnglish($this->update['message']['text']); // Converts and stores the message text.
349 |     }
350 | 
351 |     /**
352 |      * Sets the chat ID where the message or callback originated.
353 |      *
354 |      * @param string $type If "callback_query", sets chat ID for callback.
355 |      */
356 |     public function setChatId($type = "normal")
357 |     {
358 |         $this->chatID = ($type === "normal") ?
359 |             $this->update['message']['chat']['id'] :              // Retrieves chat ID from message.
360 |             $this->update['callback_query']['from']['id'];        // Retrieves chat ID from callback query if applicable.
361 |     }
362 | }
363 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/Animation.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the animation using the request method with the set parameters.
56 |             $this->request("sendAnimation", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the animation.
62 |      *
63 |      * This method sets the end flag to true, indicating that the animation has been sent,
64 |      * and then sends the animation using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the animation.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the animation using the request method with the set parameters.
73 |         return $this->request("sendAnimation", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/Audio.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the audio using the request method with the set parameters.
56 |             $this->request("sendAudio", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the audio.
62 |      *
63 |      * This method sets the end flag to true, indicating that the audio has been sent,
64 |      * and then sends the audio using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the audio.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the audio using the request method with the set parameters.
73 |         return $this->request("sendAudio", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/CopyMessage.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Copy the message using the request method with the set parameters.
56 |             $this->request("copyMessage", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and copy the message.
62 |      *
63 |      * This method sets the end flag to true, indicating that the message has been copied,
64 |      * and then copies the message using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of copying the message.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Copy the message using the request method with the set parameters.
73 |         return $this->request("copyMessage", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/CopyMessages.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Copy the message using the request method with the set parameters.
56 |             $this->request("copyMessages", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and copy the message.
62 |      *
63 |      * This method sets the end flag to true, indicating that the message has been copied,
64 |      * and then copies the message using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of copying the message.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Copy the message using the request method with the set parameters.
73 |         return $this->request("copyMessages", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/Document.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the document using the request method with the set parameters.
56 |             $this->request("sendDocument", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the document.
62 |      *
63 |      * This method sets the end flag to true, indicating that the document has been sent,
64 |      * and then sends the document using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the document.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the document using the request method with the set parameters.
73 |         return $this->request("sendDocument", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/ForwardMessage.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the message using the request method with the set parameters.
56 |             $this->request("forwardMessage", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and forward the message.
62 |      *
63 |      * This method sets the end flag to true, indicating that the message has been forwarded,
64 |      * and then forward the message using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the message.Create ForwardMessages class
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the message using the request method with the set parameters.
73 |         return $this->request("forwardMessage", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/ForwardMessages.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the messages using the request method with the set parameters.
56 |             $this->request("forwardMessages", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and forward the messages.
62 |      *
63 |      * This method sets the end flag to true, indicating that the messages has been forwarded,
64 |      * and then forward the messages using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the messages.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the messages using the request method with the set parameters.
73 |         return $this->request("forwardMessages", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/GetUserProfilePhotos.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the request using the request method with the set parameters.
56 |             $this->request("getUserProfilePhotos", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the request.
62 |      *
63 |      * This method sets the end flag to true, indicating that the request has been sent,
64 |      * and then sends the request using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the request.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the request using the request method with the set parameters.
73 |         return $this->request("getUserProfilePhotos", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/Message.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the message using the request method with the set parameters.
56 |             $this->request("sendMessage", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the message.
62 |      *
63 |      * This method sets the end flag to true, indicating that the message has been sent,
64 |      * and then sends the message using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the message.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the message using the request method with the set parameters.
73 |         return $this->request("sendMessage", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/Photo.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the photo using the request method with the set parameters.
56 |             $this->request("sendPhoto", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the photo.
62 |      *
63 |      * This method sets the end flag to true, indicating that the photo has been sent,
64 |      * and then sends the photo using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the photo.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the photo using the request method with the set parameters.
73 |         return $this->request("sendPhoto", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendChatAction.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the chat action using the request method with the set parameters.
56 |             $this->request("sendChatAction", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the chat action.
62 |      *
63 |      * This method sets the end flag to true, indicating that the chat action has been sent,
64 |      * and then sends the chat action using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the chat action.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the chat action using the request method with the set parameters.
73 |         return $this->request("sendChatAction", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendContact.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the contact using the request method with the set parameters.
56 |             $this->request("sendContact", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the contact.
62 |      *
63 |      * This method sets the end flag to true, indicating that the contact has been sent,
64 |      * and then sends the contact using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the contact.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the contact using the request method with the set parameters.
73 |         return $this->request("sendContact", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendDice.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the dice using the request method with the set parameters.
56 |             $this->request("sendDice", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the dice.
62 |      *
63 |      * This method sets the end flag to true, indicating that the dice has been sent,
64 |      * and then sends the dice using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the dice.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the dice using the request method with the set parameters.
73 |         return $this->request("sendDice", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendLocation.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the location using the request method with the set parameters.
56 |             $this->request("sendLocation", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the location.
62 |      *
63 |      * This method sets the end flag to true, indicating that the location has been sent,
64 |      * and then sends the location using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the location.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the location using the request method with the set parameters.
73 |         return $this->request("sendLocation", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendMediaGroup.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the paid media using the request method with the set parameters.
56 |             $this->request("sendPaidMedia", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the paid media.
62 |      *
63 |      * This method sets the end flag to true, indicating that the paid media has been sent,
64 |      * and then sends the paid media using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the paid media.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the paid media using the request method with the set parameters.
73 |         return $this->request("sendPaidMedia", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendPaidMedia.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the media group using the request method with the set parameters.
56 |             $this->request("sendMediaGroup", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the media group.
62 |      *
63 |      * This method sets the end flag to true, indicating that the media group has been sent,
64 |      * and then sends the media group using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the media group.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the media group using the request method with the set parameters.
73 |         return $this->request("sendMediaGroup", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendPoll.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the poll using the request method with the set parameters.
56 |             $this->request("sendPoll", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the poll.
62 |      *
63 |      * This method sets the end flag to true, indicating that the poll has been sent,
64 |      * and then sends the poll using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the poll.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the poll using the request method with the set parameters.
73 |         return $this->request("sendPoll", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SendVenue.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the venue using the request method with the set parameters.
56 |             $this->request("sendVenue", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the venue.
62 |      *
63 |      * This method sets the end flag to true, indicating that the venue has been sent,
64 |      * and then sends the venue using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the venue.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the venue using the request method with the set parameters.
73 |         return $this->request("sendVenue", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/SetMessageReaction.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the message reaction using the request method with the set parameters.
56 |             $this->request("setMessageReaction", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the message reaction.
62 |      *
63 |      * This method sets the end flag to true, indicating that the message reaction has been sent,
64 |      * and then sends the message reaction using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the message reaction.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the message reaction using the request method with the set parameters.
73 |         return $this->request("setMessageReaction", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/Video.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the video using the request method with the set parameters.
56 |             $this->request("sendVideo", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the video.
62 |      *
63 |      * This method sets the end flag to true, indicating that the video has been sent,
64 |      * and then sends the video using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the video.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the video using the request method with the set parameters.
73 |         return $this->request("sendVideo", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Class/VideoNote.php:
--------------------------------------------------------------------------------
 1 | ended) {
55 |             // Send the video note using the request method with the set parameters.
56 |             $this->request("sendVideoNote", $this->params);
57 |         }
58 |     }
59 | 
60 |     /**
61 |      * Set the end flag and send the video note.
62 |      *
63 |      * This method sets the end flag to true, indicating that the video note has been sent,
64 |      * and then sends the video note using the request method with the set parameters.
65 |      *
66 |      * @return mixed The result of sending the video note.
67 |      */
68 |     private function setEnd()
69 |     {
70 |         // Set the end flag to true.
71 |         $this->ended = true;
72 |         // Send the video note using the request method with the set parameters.
73 |         return $this->request("sendVideoNote", $this->params);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/system/TeleCore/Traits/Caller.php:
--------------------------------------------------------------------------------
 1 | setMessage('Hello')`.
31 |      *
32 |      * @param string $method The name of the called method.
33 |      * @param array $args The arguments passed to the method.
34 |      * @return ResponseMaker Returns a new instance of the ResponseMaker class with the property set.
35 |      */
36 |     public static function __callStatic($method, $args)
37 |     {
38 |         $className = get_called_class();
39 |         $instance = new $className;
40 |         return $instance->methodCaller($instance, $method, $args);
41 |     }
42 | 
43 |     /**
44 |      * Handles dynamic method calls using the __call magic method.
45 |      *
46 |      * This method allows calling dynamic methods using a fluent interface, similar to the
47 |      * __callStatic method, but for instance methods.
48 |      *
49 |      * @param string $method The name of the called method.
50 |      * @param array $args The arguments passed to the method.
51 |      * @return ResponseMaker Returns the current instance with the property set.
52 |      */
53 |     public function __call($method, $args)
54 |     {
55 |         return $this->methodCaller($this, $method, $args);
56 |     }
57 | 
58 |     /**
59 |      * Helper method to call the appropriate setter method based on the provided method name.
60 |      *
61 |      * This method is used by the __callStatic and __call magic methods to dynamically call
62 |      * the corresponding setter method based on the provided method name. It follows a naming
63 |      * convention where the setter method name starts with "set" followed by the capitalized
64 |      * property name.
65 |      *
66 |      * @param object $object The instance of the ResponseMaker class.
67 |      * @param string $method The name of the called method.
68 |      * @param array $args The arguments passed to the method.
69 |      * @return mixed Returns the result of calling the appropriate setter method.
70 |      */
71 |     private function methodCaller($object, $method, $args)
72 |     {
73 |         $suffix = 'set';
74 |         $methodName = $suffix . strtoupper($method[0]) . substr($method, 1);
75 |         return call_user_func_array(array($object, $methodName), $args);
76 |     }
77 | }
78 | 


--------------------------------------------------------------------------------
/system/TeleCore/Traits/Request.php:
--------------------------------------------------------------------------------
 1 |  API_URL]);
38 | 
39 |         // Set empty parameters array if none provided
40 |         if (!$parameters) {
41 |             $parameters = [];
42 |         }
43 |         // Add the method to the parameters
44 |         $parameters["method"] = $method;
45 | 
46 |         // Send POST request with JSON-encoded parameters
47 |         $response = $client->post('', [
48 |             'json' => $parameters,
49 |             'headers' => [
50 |                 'Content-Type' => 'application/json',
51 |             ],
52 |             'connect_timeout' => 5, // Timeout for connection
53 |             'timeout' => 60, // Timeout for execution
54 |         ]);
55 | 
56 |         // Get response body
57 |         $result = $response->getBody()->getContents();
58 | 
59 |         // Return the result
60 |         return $result;
61 |     }
62 | }
63 | 


--------------------------------------------------------------------------------
/system/TeleCore/Traits/Setters.php:
--------------------------------------------------------------------------------
  1 | params['business_connection_id'] = $business_connection_id;
 32 |         return $this;
 33 |     }
 34 | 
 35 |     /**
 36 |      * Set the chat ID for the message.
 37 |      *
 38 |      * @param mixed $chat_id The ID of the chat.
 39 |      * @return this Returns the current instance with the chat ID set.
 40 |      */
 41 |     private function setChatId($chat_id)
 42 |     {
 43 |         $this->params['chat_id'] = $chat_id;
 44 |         return $this;
 45 |     }
 46 | 
 47 |     /**
 48 |      * Set the message thread ID for the message.
 49 |      *
 50 |      * @param mixed $message_thread_id The ID of the message thread.
 51 |      * @return this Returns the current instance with the message thread ID set.
 52 |      */
 53 |     private function setMessageThreadId($message_thread_id)
 54 |     {
 55 |         $this->params['message_thread_id'] = $message_thread_id;
 56 |         return $this;
 57 |     }
 58 | 
 59 |     /**
 60 |      * Set the entities for the message.
 61 |      *
 62 |      * @param array $entities The entities associated with the message.
 63 |      * @return this Returns the current instance with the entities set.
 64 |      */
 65 |     private function setEntities($entities)
 66 |     {
 67 |         $this->params['entities'] = $entities;
 68 |         return $this;
 69 |     }
 70 | 
 71 |     /**
 72 |      * Set the link preview options for the message.
 73 |      *
 74 |      * @param mixed $link_preview_options The link preview options for the message.
 75 |      * @return this Returns the current instance with the link preview options set.
 76 |      */
 77 |     private function setLinkPreviewOptions($link_preview_options)
 78 |     {
 79 |         $this->params['link_preview_options'] = $link_preview_options;
 80 |         return $this;
 81 |     }
 82 | 
 83 |     /**
 84 |      * Set whether to disable notification for the message.
 85 |      *
 86 |      * @param bool $disable_notification Whether to disable notification.
 87 |      * @return this Returns the current instance with the notification settings set.
 88 |      */
 89 |     private function setDisableNotification($disable_notification)
 90 |     {
 91 |         $this->params['disable_notification'] = $disable_notification;
 92 |         return $this;
 93 |     }
 94 | 
 95 |     /**
 96 |      * Set the reply parameters for the message.
 97 |      *
 98 |      * @param array $reply_parameters The parameters for replying to the message.
 99 |      * @return this Returns the current instance with the reply parameters set.
100 |      */
101 |     private function setReplyParameters($reply_parameters)
102 |     {
103 |         $this->params['reply_parameters'] = $reply_parameters;
104 |         return $this;
105 |     }
106 | 
107 |     /**
108 |      * Set the reply markup for the message.
109 |      *
110 |      * @param mixed $reply_markup The reply markup for the message.
111 |      * @return this Returns the current instance with the reply markup set.
112 |      */
113 |     private function setReplyMarkup($reply_markup)
114 |     {
115 |         $this->params['reply_markup'] = $reply_markup;
116 |         return $this;
117 |     }
118 | 
119 |     /**
120 |      * Set whether to protect content for the message.
121 |      *
122 |      * @param bool $protect_content Whether to protect content.
123 |      * @return this Returns the current instance with the content protection settings set.
124 |      */
125 |     private function setProtectContent($protect_content)
126 |     {
127 |         $this->params['protect_content'] = $protect_content;
128 |         return $this;
129 |     }
130 | 
131 |     /**
132 |      * Set the text content of the message.
133 |      *
134 |      * @param string $text The text content of the message.
135 |      * @return this Returns the current instance with the text content set.
136 |      */
137 |     private function setText($text)
138 |     {
139 |         $this->params['text'] = $text;
140 |         return $this;
141 |     }
142 | 
143 |     /**
144 |      * Set the parse mode for the message.
145 |      *
146 |      * @param string $parse_mode The parse mode for the message.
147 |      * @return this Returns the current instance with the parse mode set.
148 |      */
149 |     private function setParseMode($parse_mode)
150 |     {
151 |         $this->params['parse_mode'] = $parse_mode;
152 |         return $this;
153 |     }
154 | 
155 |     /**
156 |      * Set the chat ID of the sender.
157 |      *
158 |      * @param int $from_chat_id The chat ID of the sender.
159 |      * @return this Returns the current instance with the sender's chat ID set.
160 |      */
161 |     private function setFromChatId($from_chat_id)
162 |     {
163 |         $this->params['from_chat_id'] = $from_chat_id;
164 |         return $this;
165 |     }
166 | 
167 |     /**
168 |      * Set the message ID.
169 |      *
170 |      * @param int $message_id The ID of the message.
171 |      * @return this Returns the current instance with the message ID set.
172 |      */
173 |     private function setMessageId($message_id)
174 |     {
175 |         $this->params['message_id'] = $message_id;
176 |         return $this;
177 |     }
178 | 
179 |     /**
180 |      * Set an array of message IDs.
181 |      *
182 |      * @param array $message_ids An array of message IDs.
183 |      * @return this Returns the current instance with the message IDs set.
184 |      */
185 |     private function setMessageIds(array $message_ids)
186 |     {
187 |         $this->params['message_ids'] = $message_ids;
188 |         return $this;
189 |     }
190 | 
191 |     /**
192 |      * Set a caption for the message.
193 |      *
194 |      * @param string $caption The caption for the message.
195 |      * @return this Returns the current instance with the caption set.
196 |      */
197 |     private function setCaption($caption)
198 |     {
199 |         $this->params['caption'] = $caption;
200 |         return $this;
201 |     }
202 | 
203 |     /**
204 |      * Set entities for the caption.
205 |      *
206 |      * @param array $caption_entities An array of entities for the caption.
207 |      * @return this Returns the current instance with the caption entities set.
208 |      */
209 |     private function setCaptionEntities($caption_entities)
210 |     {
211 |         $this->params['caption_entities'] = $caption_entities;
212 |         return $this;
213 |     }
214 | 
215 |     /**
216 |      * Set a photo for the message.
217 |      *
218 |      * @param string $photo The photo for the message.
219 |      * @return $this Returns the current instance with the photo set.
220 |      */
221 |     private function setPhoto($photo)
222 |     {
223 |         $this->params['photo'] = $photo; // Set the photo parameter.
224 |         return $this; // Return the current instance.
225 |     }
226 | 
227 |     /**
228 |      * Set whether the message has a spoiler.
229 |      *
230 |      * @param bool $has_spoiler A boolean value indicating whether the message has a spoiler.
231 |      * @return $this Returns the current instance with the spoiler flag set.
232 |      */
233 |     private function setHasSpoiler($has_spoiler)
234 |     {
235 |         $this->params['has_spoiler'] = $has_spoiler; // Set the has_spoiler parameter.
236 |         return $this; // Return the current instance.
237 |     }
238 | 
239 |     /**
240 |      * Set the audio for the message.
241 |      *
242 |      * @param mixed $audio The audio for the message.
243 |      * @return $this Returns the current instance with the audio set.
244 |      */
245 |     private function setAudio($audio)
246 |     {
247 |         $this->params['audio'] = $audio; // Set the audio parameter.
248 |         return $this; // Return the current instance.
249 |     }
250 | 
251 |     /**
252 |      * Set the duration of the audio.
253 |      *
254 |      * @param int $duration The duration of the audio.
255 |      * @return $this Returns the current instance with the duration set.
256 |      */
257 |     private function setDuration($duration)
258 |     {
259 |         $this->params['duration'] = $duration; // Set the duration parameter.
260 |         return $this; // Return the current instance.
261 |     }
262 | 
263 |     /**
264 |      * Set the performer of the audio.
265 |      *
266 |      * @param string $performer The performer of the audio.
267 |      * @return $this Returns the current instance with the performer set.
268 |      */
269 |     private function setPerformer($performer)
270 |     {
271 |         $this->params['performer'] = $performer; // Set the performer parameter.
272 |         return $this; // Return the current instance.
273 |     }
274 | 
275 |     /**
276 |      * Set the title of the audio.
277 |      *
278 |      * @param string $title The title of the audio.
279 |      * @return $this Returns the current instance with the title set.
280 |      */
281 |     private function setTitle($title)
282 |     {
283 |         $this->params['title'] = $title; // Set the title parameter.
284 |         return $this; // Return the current instance.
285 |     }
286 | 
287 |     /**
288 |      * Set the thumbnail for the message.
289 |      *
290 |      * @param string $thumbnail The thumbnail for the message.
291 |      * @return $this Returns the current instance with the thumbnail set.
292 |      */
293 |     private function setThumbnail($thumbnail)
294 |     {
295 |         $this->params['thumbnail'] = $thumbnail; // Set the thumbnail parameter.
296 |         return $this; // Return the current instance.
297 |     }
298 | 
299 |     /**
300 |      * Set the document for the message.
301 |      *
302 |      * @param mixed $document The document for the message.
303 |      * @return $this Returns the current instance with the document set.
304 |      */
305 |     private function setDocument($document)
306 |     {
307 |         $this->params['document'] = $document; // Set the document parameter.
308 |         return $this; // Return the current instance.
309 |     }
310 | 
311 |     /**
312 |      * Set whether to disable content type detection.
313 |      *
314 |      * @param bool $disable_content_type_detection A boolean value indicating whether to disable content type detection.
315 |      * @return $this Returns the current instance with the flag set.
316 |      */
317 |     private function setDisableContentTypeDetection($disable_content_type_detection)
318 |     {
319 |         $this->params['disable_content_type_detection'] = $disable_content_type_detection; // Set the disable_content_type_detection parameter.
320 |         return $this; // Return the current instance.
321 |     }
322 | 
323 |     /**
324 |      * Set the video for the message.
325 |      *
326 |      * @param mixed $video The video for the message.
327 |      * @return $this Returns the current instance with the video set.
328 |      */
329 |     private function setVideo($video)
330 |     {
331 |         $this->params['video'] = $video; // Set the video parameter.
332 |         return $this; // Return the current instance.
333 |     }
334 | 
335 |     /**
336 |      * Set the width of the message.
337 |      *
338 |      * @param int $width The width of the message.
339 |      * @return $this Returns the current instance with the width set.
340 |      */
341 |     private function setWidth($width)
342 |     {
343 |         $this->params['width'] = $width; // Set the width parameter.
344 |         return $this; // Return the current instance.
345 |     }
346 | 
347 |     /**
348 |      * Set the height of the message.
349 |      *
350 |      * @param int $height The height of the message.
351 |      * @return $this Returns the current instance with the height set.
352 |      */
353 |     private function setHeight($height)
354 |     {
355 |         $this->params['height'] = $height; // Set the height parameter.
356 |         return $this; // Return the current instance.
357 |     }
358 | 
359 |     /**
360 |      * Set whether the message supports streaming.
361 |      *
362 |      * @param bool $supports_streaming A boolean value indicating whether the message supports streaming.
363 |      * @return $this Returns the current instance with the flag set.
364 |      */
365 |     private function setSupportsStreaming($supports_streaming)
366 |     {
367 |         $this->params['supports_streaming'] = $supports_streaming; // Set the supports_streaming parameter.
368 |         return $this; // Return the current instance.
369 |     }
370 | 
371 |     /**
372 |      * Set the animation for the message.
373 |      *
374 |      * @param mixed $animation The animation for the message.
375 |      * @return $this Returns the current instance with the animation set.
376 |      */
377 |     private function setAnimation($animation)
378 |     {
379 |         $this->params['animation'] = $animation; // Set the animation parameter.
380 |         return $this; // Return the current instance.
381 |     }
382 | 
383 |     /**
384 |      * Set the voice for the message.
385 |      *
386 |      * @param mixed $voice The voice to set.
387 |      * @return $this Returns the current instance with the voice set.
388 |      */
389 |     private function setVoice($voice)
390 |     {
391 |         // Set the voice parameter.
392 |         $this->params['voice'] = $voice;
393 |         // Return the current instance.
394 |         return $this;
395 |     }
396 | 
397 |     /**
398 |      * Set the message effect ID for the message.
399 |      *
400 |      * @param mixed $message_effect_id The message effect ID to set.
401 |      * @return $this Returns the current instance with the message effect ID set.
402 |      */
403 |     private function setMessageEffectId($message_effect_id)
404 |     {
405 |         // Set the message effect ID parameter.
406 |         $this->params['message_effect_id'] = $message_effect_id;
407 |         // Return the current instance.
408 |         return $this;
409 |     }
410 | 
411 |     /**
412 |      * Set the length for the message.
413 |      *
414 |      * @param mixed $length The length to set.
415 |      * @return $this Returns the current instance with the length set.
416 |      */
417 |     private function setLength($length)
418 |     {
419 |         // Set the length parameter.
420 |         $this->params['length'] = $length;
421 |         // Return the current instance.
422 |         return $this;
423 |     }
424 | 
425 |     /**
426 |      * Set the video note for the message.
427 |      *
428 |      * @param mixed $video_note The video note to set.
429 |      * @return $this Returns the current instance with the video note set.
430 |      */
431 |     private function setVideoNote($video_note)
432 |     {
433 |         // Set the video note parameter.
434 |         $this->params['video_note'] = $video_note;
435 |         // Return the current instance.
436 |         return $this;
437 |     }
438 | 
439 |     /**
440 |      * Set the allow paid broadcast flag for the message.
441 |      *
442 |      * @param mixed $allow_paid_broadcast The flag to allow or disallow paid broadcasts.
443 |      * @return $this Returns the current instance with the allow paid broadcast flag set.
444 |      */
445 |     private function setAllowPaidBroadcast($allow_paid_broadcast)
446 |     {
447 |         // Set the allow paid broadcast parameter.
448 |         $this->params['allow_paid_broadcast'] = $allow_paid_broadcast;
449 |         // Return the current instance for method chaining.
450 |         return $this;
451 |     }
452 | 
453 |     /**
454 |      * Set the star count for the message.
455 |      *
456 |      * @param mixed $star_count The number of stars to set.
457 |      * @return $this Returns the current instance with the star count set.
458 |      */
459 |     private function setStarCount($star_count)
460 |     {
461 |         // Set the star count parameter.
462 |         $this->params['star_count'] = $star_count;
463 |         // Return the current instance for method chaining.
464 |         return $this;
465 |     }
466 | 
467 |     /**
468 |      * Set the media for the message.
469 |      *
470 |      * @param mixed $media The media to set for the message.
471 |      * @return $this Returns the current instance with the media set.
472 |      */
473 |     private function setMedia($media)
474 |     {
475 |         // Set the media parameter.
476 |         $this->params['media'] = $media;
477 |         // Return the current instance for method chaining.
478 |         return $this;
479 |     }
480 | 
481 |     /**
482 |      * Set the payload for the message.
483 |      *
484 |      * @param mixed $payload The payload to set for the message.
485 |      * @return $this Returns the current instance with the payload set.
486 |      */
487 |     private function setPayload($payload)
488 |     {
489 |         // Set the payload parameter.
490 |         $this->params['payload'] = $payload;
491 |         // Return the current instance for method chaining.
492 |         return $this;
493 |     }
494 | 
495 |     /**
496 |      * Set whether to show the caption above the media for the message.
497 |      *
498 |      * @param mixed $show_caption_above_media Whether to show the caption above the media.
499 |      * @return $this Returns the current instance with the show_caption_above_media flag set.
500 |      */
501 |     private function setShowCaptionAboveMedia($show_caption_above_media)
502 |     {
503 |         // Set the show_caption_above_media parameter.
504 |         $this->params['show_caption_above_media'] = $show_caption_above_media;
505 |         // Return the current instance for method chaining.
506 |         return $this;
507 |     }
508 | 
509 |     /**
510 |      * Set the latitude for the message.
511 |      *
512 |      * @param mixed $latitude The latitude value to set.
513 |      * @return $this Returns the current instance with the latitude set.
514 |      */
515 |     private function setLatitude($latitude)
516 |     {
517 |         // Set the latitude parameter.
518 |         $this->params['latitude'] = $latitude;
519 |         // Return the current instance for method chaining.
520 |         return $this;
521 |     }
522 | 
523 |     /**
524 |      * Set the longitude for the message.
525 |      *
526 |      * @param mixed $longitude The longitude value to set.
527 |      * @return $this Returns the current instance with the longitude set.
528 |      */
529 |     private function setLongitude($longitude)
530 |     {
531 |         // Set the longitude parameter.
532 |         $this->params['longitude'] = $longitude;
533 |         // Return the current instance for method chaining.
534 |         return $this;
535 |     }
536 | 
537 |     /**
538 |      * Set the horizontal accuracy for the message.
539 |      *
540 |      * @param mixed $horizontal_accuracy The horizontal accuracy value to set.
541 |      * @return $this Returns the current instance with the horizontal accuracy set.
542 |      */
543 |     private function setHorizontalAccuracy($horizontal_accuracy)
544 |     {
545 |         // Set the horizontal accuracy parameter.
546 |         $this->params['horizontal_accuracy'] = $horizontal_accuracy;
547 |         // Return the current instance for method chaining.
548 |         return $this;
549 |     }
550 | 
551 |     /**
552 |      * Set the live period for the message.
553 |      *
554 |      * @param mixed $live_period The live period value to set.
555 |      * @return $this Returns the current instance with the live period set.
556 |      */
557 |     private function setLivePeriod($live_period)
558 |     {
559 |         // Set the live period parameter.
560 |         $this->params['live_period'] = $live_period;
561 |         // Return the current instance for method chaining.
562 |         return $this;
563 |     }
564 | 
565 |     /**
566 |      * Set the heading for the message.
567 |      *
568 |      * @param mixed $heading The heading value to set.
569 |      * @return $this Returns the current instance with the heading set.
570 |      */
571 |     private function setHeading($heading)
572 |     {
573 |         // Set the heading parameter.
574 |         $this->params['heading'] = $heading;
575 |         // Return the current instance for method chaining.
576 |         return $this;
577 |     }
578 | 
579 |     /**
580 |      * Set the proximity alert radius for the message.
581 |      *
582 |      * @param mixed $proximity_alert_radius The proximity alert radius value to set.
583 |      * @return $this Returns the current instance with the proximity alert radius set.
584 |      */
585 |     private function setProximityAlertRadius($proximity_alert_radius)
586 |     {
587 |         // Set the proximity alert radius parameter.
588 |         $this->params['proximity_alert_radius'] = $proximity_alert_radius;
589 |         // Return the current instance for method chaining.
590 |         return $this;
591 |     }
592 | 
593 |     /**
594 |      * Set the address for the message.
595 |      *
596 |      * @param mixed $address The address value to set.
597 |      * @return $this Returns the current instance with the address set.
598 |      */
599 |     private function setAddress($address)
600 |     {
601 |         // Set the address parameter.
602 |         $this->params['address'] = $address;
603 |         // Return the current instance for method chaining.
604 |         return $this;
605 |     }
606 | 
607 |     /**
608 |      * Set the Foursquare ID for the message.
609 |      *
610 |      * @param mixed $foursquare_id The Foursquare ID value to set.
611 |      * @return $this Returns the current instance with the Foursquare ID set.
612 |      */
613 |     private function setFoursquareId($foursquare_id)
614 |     {
615 |         // Set the Foursquare ID parameter.
616 |         $this->params['foursquare_id'] = $foursquare_id;
617 |         // Return the current instance for method chaining.
618 |         return $this;
619 |     }
620 | 
621 |     /**
622 |      * Set the Foursquare type for the message.
623 |      *
624 |      * @param mixed $foursquare_type The Foursquare type value to set.
625 |      * @return $this Returns the current instance with the Foursquare type set.
626 |      */
627 |     private function setFoursquareType($foursquare_type)
628 |     {
629 |         // Set the Foursquare type parameter.
630 |         $this->params['foursquare_type'] = $foursquare_type;
631 |         // Return the current instance for method chaining.
632 |         return $this;
633 |     }
634 | 
635 |     /**
636 |      * Set the Google Place ID for the message.
637 |      *
638 |      * @param mixed $google_place_id The Google Place ID value to set.
639 |      * @return $this Returns the current instance with the Google Place ID set.
640 |      */
641 |     private function setGooglePlaceId($google_place_id)
642 |     {
643 |         // Set the Google Place ID parameter.
644 |         $this->params['google_place_id'] = $google_place_id;
645 |         // Return the current instance for method chaining.
646 |         return $this;
647 |     }
648 | 
649 |     /**
650 |      * Set the Google Place type for the message.
651 |      *
652 |      * @param mixed $google_place_type The Google Place type value to set.
653 |      * @return $this Returns the current instance with the Google Place type set.
654 |      */
655 |     private function setGooglePlaceType($google_place_type)
656 |     {
657 |         // Set the Google Place type parameter.
658 |         $this->params['google_place_type'] = $google_place_type;
659 |         // Return the current instance for method chaining.
660 |         return $this;
661 |     }
662 | 
663 |     /**
664 |      * Set the phone number for the message.
665 |      *
666 |      * @param mixed $phone_number The phone number value to set.
667 |      * @return $this Returns the current instance with the phone number set.
668 |      */
669 |     private function setPhoneNumber($phone_number)
670 |     {
671 |         // Set the phone number parameter.
672 |         $this->params['phone_number'] = $phone_number;
673 |         // Return the current instance for method chaining.
674 |         return $this;
675 |     }
676 | 
677 |     /**
678 |      * Set the first name for the message.
679 |      *
680 |      * @param mixed $first_name The first name value to set.
681 |      * @return $this Returns the current instance with the first name set.
682 |      */
683 |     private function setFirstName($first_name)
684 |     {
685 |         // Set the first name parameter.
686 |         $this->params['first_name'] = $first_name;
687 |         // Return the current instance for method chaining.
688 |         return $this;
689 |     }
690 | 
691 |     /**
692 |      * Set the last name for the message.
693 |      *
694 |      * @param mixed $last_name The last name value to set.
695 |      * @return $this Returns the current instance with the last name set.
696 |      */
697 |     private function setLastName($last_name)
698 |     {
699 |         // Set the last name parameter.
700 |         $this->params['last_name'] = $last_name;
701 |         // Return the current instance for method chaining.
702 |         return $this;
703 |     }
704 | 
705 |     /**
706 |      * Set the vCard for the message.
707 |      *
708 |      * @param mixed $vcard The vCard value to set.
709 |      * @return $this Returns the current instance with the vCard set.
710 |      */
711 |     private function setVcard($vcard)
712 |     {
713 |         // Set the vCard parameter.
714 |         $this->params['vcard'] = $vcard;
715 |         // Return the current instance for method chaining.
716 |         return $this;
717 |     }
718 | 
719 |     /**
720 |      * Set the question for the message.
721 |      *
722 |      * @param mixed $question The question value to set.
723 |      * @return $this Returns the current instance with the question set.
724 |      */
725 |     private function setQuestion($question)
726 |     {
727 |         // Set the question parameter.
728 |         $this->params['question'] = $question;
729 |         // Return the current instance for method chaining.
730 |         return $this;
731 |     }
732 | 
733 |     /**
734 |      * Set the question parse mode for the message.
735 |      *
736 |      * @param mixed $question_parse_mode The question parse mode value to set.
737 |      * @return $this Returns the current instance with the question parse mode set.
738 |      */
739 |     private function setQuestionParseMode($question_parse_mode)
740 |     {
741 |         // Set the question parse mode parameter.
742 |         $this->params['question_parse_mode'] = $question_parse_mode;
743 |         // Return the current instance for method chaining.
744 |         return $this;
745 |     }
746 | 
747 |     /**
748 |      * Set the question entities for the message.
749 |      *
750 |      * @param mixed $question_entities The question entities value to set.
751 |      * @return $this Returns the current instance with the question entities set.
752 |      */
753 |     private function setQuestionEntities($question_entities)
754 |     {
755 |         // Set the question entities parameter.
756 |         $this->params['question_entities'] = $question_entities;
757 |         // Return the current instance for method chaining.
758 |         return $this;
759 |     }
760 | 
761 |     /**
762 |      * Set the anonymity status for the message.
763 |      *
764 |      * @param mixed $is_anonymous The anonymity status value to set.
765 |      * @return $this Returns the current instance with the anonymity status set.
766 |      */
767 |     private function setIsAnonymous($is_anonymous)
768 |     {
769 |         // Set the anonymity status parameter.
770 |         $this->params['is_anonymous'] = $is_anonymous;
771 |         // Return the current instance for method chaining.
772 |         return $this;
773 |     }
774 | 
775 |     /**
776 |      * Set the multiple answers permission for the message.
777 |      *
778 |      * @param mixed $allows_multiple_answers The multiple answers permission value to set.
779 |      * @return $this Returns the current instance with the multiple answers permission set.
780 |      */
781 |     private function setAllowsMultipleAnswers($allows_multiple_answers)
782 |     {
783 |         // Set the multiple answers permission parameter.
784 |         $this->params['allows_multiple_answers'] = $allows_multiple_answers;
785 |         // Return the current instance for method chaining.
786 |         return $this;
787 |     }
788 | 
789 |     /**
790 |      * Set the correct option ID for the message.
791 |      *
792 |      * @param mixed $correct_option_id The correct option ID value to set.
793 |      * @return $this Returns the current instance with the correct option ID set.
794 |      */
795 |     private function setCorrectOptionId($correct_option_id)
796 |     {
797 |         // Set the correct option ID parameter.
798 |         $this->params['correct_option_id'] = $correct_option_id;
799 |         // Return the current instance for method chaining.
800 |         return $this;
801 |     }
802 | 
803 |     /**
804 |      * Set the explanation for the message.
805 |      *
806 |      * @param mixed $explanation The explanation value to set.
807 |      * @return $this Returns the current instance with the explanation set.
808 |      */
809 |     private function setExplanation($explanation)
810 |     {
811 |         // Set the explanation parameter.
812 |         $this->params['explanation'] = $explanation;
813 |         // Return the current instance for method chaining.
814 |         return $this;
815 |     }
816 | 
817 |     /**
818 |      * Set the explanation parse mode for the message.
819 |      *
820 |      * @param mixed $explanation_parse_mode The explanation parse mode value to set.
821 |      * @return $this Returns the current instance with the explanation parse mode set.
822 |      */
823 |     private function setExplanationParseMode($explanation_parse_mode)
824 |     {
825 |         // Set the explanation parse mode parameter.
826 |         $this->params['explanation_parse_mode'] = $explanation_parse_mode;
827 |         // Return the current instance for method chaining.
828 |         return $this;
829 |     }
830 | 
831 |     /**
832 |      * Set the explanation entities for the message.
833 |      *
834 |      * @param mixed $explanation_entities The explanation entities value to set.
835 |      * @return $this Returns the current instance with the explanation entities set.
836 |      */
837 |     private function setExplanationEntities($explanation_entities)
838 |     {
839 |         // Set the explanation entities parameter.
840 |         $this->params['explanation_entities'] = $explanation_entities;
841 |         // Return the current instance for method chaining.
842 |         return $this;
843 |     }
844 | 
845 |     /**
846 |      * Set the open period for the message.
847 |      *
848 |      * @param mixed $open_period The open period value to set.
849 |      * @return $this Returns the current instance with the open period set.
850 |      */
851 |     private function setOpenPeriod($open_period)
852 |     {
853 |         // Set the open period parameter.
854 |         $this->params['open_period'] = $open_period;
855 |         // Return the current instance for method chaining.
856 |         return $this;
857 |     }
858 | 
859 |     /**
860 |      * Set the close date for the message.
861 |      *
862 |      * @param mixed $close_date The close date value to set.
863 |      * @return $this Returns the current instance with the close date set.
864 |      */
865 |     private function setCloseDate($close_date)
866 |     {
867 |         // Set the close date parameter.
868 |         $this->params['close_date'] = $close_date;
869 |         // Return the current instance for method chaining.
870 |         return $this;
871 |     }
872 | 
873 |     /**
874 |      * Set the closed status for the message.
875 |      *
876 |      * @param mixed $is_closed The closed status value to set.
877 |      * @return $this Returns the current instance with the closed status set.
878 |      */
879 |     private function setIsClosed($is_closed)
880 |     {
881 |         // Set the closed status parameter.
882 |         $this->params['is_closed'] = $is_closed;
883 |         // Return the current instance for method chaining.
884 |         return $this;
885 |     }
886 | 
887 |     /**
888 |      * Set the emoji for the message.
889 |      *
890 |      * @param mixed $emoji The emoji value to set.
891 |      * @return $this Returns the current instance with the emoji set.
892 |      */
893 |     private function setEmoji($emoji)
894 |     {
895 |         // Set the emoji parameter.
896 |         $this->params['emoji'] = $emoji;
897 |         // Return the current instance for method chaining.
898 |         return $this;
899 |     }
900 | 
901 |     /**
902 |      * Set the action for the message.
903 |      *
904 |      * @param mixed $action The action value to set.
905 |      * @return $this Returns the current instance with the action set.
906 |      */
907 |     private function setAction($action)
908 |     {
909 |         // Set the action parameter.
910 |         $this->params['action'] = $action;
911 |         // Return the current instance for method chaining.
912 |         return $this;
913 |     }
914 | }
915 | 


--------------------------------------------------------------------------------