diff --git a/build_docs.php b/build_docs.php index 1466d3be..10656750 100755 --- a/build_docs.php +++ b/build_docs.php @@ -61,6 +61,9 @@ description: Documentation of old mtproto layers '.$layer_list); +$doc = new \danog\MadelineProto\AnnotationsBuilder($docs[1]); +$doc->mk_annotations(); + foreach ($docs as $settings) { $doc = new \danog\MadelineProto\DocsBuilder($settings); $doc->mk_docs(); diff --git a/composer.json b/composer.json index 9a471c20..8ce2d3c7 100644 --- a/composer.json +++ b/composer.json @@ -6,11 +6,14 @@ "homepage": "https://daniil.it/MadelineProto", "keywords": ["telegram", "mtproto", "protocol", "bytes", "messenger", "client", "PHP", "video", "stickers", "audio", "files", "GB"], "require": { + "php": ">=5.6.0", "danog/phpstruct": "^1.2", "phpseclib/phpseclib": "dev-master|^2.0.4", - "php": ">=5.6.0", "vlucas/phpdotenv": "^2.4" }, + "require-dev": { + "phpdocumentor/reflection-docblock": "^3.1" + }, "authors": [ { "name": "Daniil Gentili", diff --git a/composer.lock b/composer.lock index 951c4a31..863175ed 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2620601f51f3b8074fc1fe4b606a9054", - "content-hash": "055f6111941ad34ac71efe5c718ff3d6", + "hash": "e8bbb62792931576147b60ac9015be7a", + "content-hash": "88f022c06bcba63b61978fccad258d1a", "packages": [ { "name": "danog/phpstruct", @@ -314,7 +314,204 @@ "time": "2016-09-01 10:05:43" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-09-30 07:12:33" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2016-11-25 06:54:22" + }, + { + "name": "webmozart/assert", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-11-23 20:04:58" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": { diff --git a/docs/index.md b/docs/index.md index 3bf321f3..74c04a16 100644 --- a/docs/index.md +++ b/docs/index.md @@ -28,9 +28,18 @@ The MadelineProto API documentations (old layers) can be found [here](https://gi ## Usage +### Installation + +``` +git clone https://github.com/danog/MadelineProto +cd MadelineProto +``` + +Now copy .env.example to .env, edit the its values, read the docs and take a look at testing.php, bot.php. + ### Dependencies -This project depends on [PHPStruct](https://github.com/danog/PHPStruct), [phpseclib](https://github.com/phpseclib/phpseclib), https://packagist.org/packages/paragonie/constant_time_encoding and https://packagist.org/packages/paragonie/random_compat +This project depends on [PHPStruct](https://github.com/danog/PHPStruct), [phpseclib](https://github.com/phpseclib/phpseclib) To install dependencies install composer and run: ``` diff --git a/src/danog/MadelineProto/APIFactory.php b/src/danog/MadelineProto/APIFactory.php index 2c569a03..5cdad79d 100644 --- a/src/danog/MadelineProto/APIFactory.php +++ b/src/danog/MadelineProto/APIFactory.php @@ -14,6 +14,66 @@ namespace danog\MadelineProto; class APIFactory { + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var channels + */ + public $channels; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var help + */ + public $help; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var upload + */ + public $upload; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var photos + */ + public $photos; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var updates + */ + public $updates; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var messages + */ + public $messages; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var contacts + */ + public $contacts; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var users + */ + public $users; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var account + */ + public $account; + /** + * @internal this is a internal property generated by build_docs.php, dont change manually + * + * @var auth + */ + public $auth; public $namespace; public $API; diff --git a/src/danog/MadelineProto/AnnotationsBuilder.php b/src/danog/MadelineProto/AnnotationsBuilder.php new file mode 100644 index 00000000..e4305e04 --- /dev/null +++ b/src/danog/MadelineProto/AnnotationsBuilder.php @@ -0,0 +1,137 @@ +. +*/ + +namespace danog\MadelineProto; + +use phpDocumentor\Reflection\DocBlockFactory; + +class AnnotationsBuilder +{ + use \danog\MadelineProto\TL\TL; + + public function __construct($settings) + { + $this->construct_TL($settings['tl_schema']); + $this->settings = $settings; + } + + public function mk_annotations() + { + \danog\MadelineProto\Logger::log('Generating annotations...'); + $this->setProperties(); + $this->createInternalClasses(); + } + + /** + * Open file of class APIFactory + * Insert properties + * save the file with new content. + */ + private function setProperties() + { + \danog\MadelineProto\Logger::log('Generating properties...'); + $fixture = DocBlockFactory::createInstance(); + $class = new \ReflectionClass(APIFactory::class); + $content = file_get_contents($filename = $class->getFileName()); + foreach ($class->getProperties() as $property) { + if ($raw_docblock = $property->getDocComment()) { + $docblock = $fixture->create($raw_docblock); + if ($docblock->hasTag('internal')) { + $content = str_replace("\n ".$raw_docblock."\n public $".$property->getName().';', '', $content); + } + } + } + foreach ($this->methods->method_namespace as $namespace) { + $content = preg_replace( + '/(class( \w+[,]?){0,}\n{\n)/', + '${1}'. + " /**\n". + " * @internal this is a internal property generated by build_docs.php, don't change manually\n". + " *\n". + " * @var $namespace\n". + " */\n". + " public \$$namespace;\n", + $content + ); + } + file_put_contents($filename, $content); + } + + /** + * Create file InternalDoc with all interfaces. + */ + private function createInternalClasses() + { + \danog\MadelineProto\Logger::log('Creating internal classes...'); + $handle = fopen(dirname(__FILE__).'/InternalDoc.php', 'w'); + foreach ($this->methods->method as $key => $rmethod) { + if (!strpos($rmethod, '.')) { + continue; + } + list($namespace, $method) = explode('.', $rmethod); + if (!in_array($namespace, $this->methods->method_namespace)) { + continue; + } + $type = str_replace(['.', '<', '>'], ['_', '_of_', ''], $this->methods->type[$key]); + foreach ($this->methods->params[$key] as $param) { + if (in_array($param['name'], ['flags', 'random_id'])) { + continue; + } + $stype = 'type'; + if (isset($param['subtype'])) { + $stype = 'subtype'; + } + $ptype = str_replace('.', '_', $param[$stype]); + switch ($ptype) { + case 'true': + case 'false': + $ptype = 'boolean'; + } + $internalDoc[$namespace][$method]['attr'][$param['name']] = $ptype; + } + if ($type == 'Bool') { + $type = strtolower($type); + } + $internalDoc[$namespace][$method]['return'] = $type; + } + fwrite($handle, " $methods) { + fwrite($handle, "\ninterface $namespace\n{"); + foreach ($methods as $method => $properties) { + fwrite($handle, "\n /**\n"); + if (isset($properties['attr'])) { + fwrite($handle, " * @param array params [\n"); + foreach ($properties['attr'] as $name => $type) { + fwrite($handle, " * $type $name,\n"); + } + fwrite($handle, " * ]\n"); + fwrite($handle, " *\n"); + } + fwrite($handle, " * @return {$properties['return']}\n"); + fwrite($handle, " */\n"); + fwrite($handle, " public function $method("); + if (isset($properties['attr'])) { + fwrite($handle, 'array $params'); + } + fwrite($handle, ");\n"); + } + fwrite($handle, "}\n"); + } + fclose($handle); + } +} diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php new file mode 100644 index 00000000..00b9dad4 --- /dev/null +++ b/src/danog/MadelineProto/InternalDoc.php @@ -0,0 +1,1790 @@ +