{"id":15025468,"url":"https://github.com/kadet1090/nucleus","last_synced_at":"2025-04-09T20:04:04.152Z","repository":{"id":57003791,"uuid":"64169159","full_name":"kadet1090/nucleus","owner":"kadet1090","description":"Asynchronous XMPP Library for PHP based on React","archived":false,"fork":false,"pushed_at":"2017-03-28T12:45:27.000Z","size":220,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-09T20:03:56.747Z","etag":null,"topics":["jabber","php","php-7","xmpp-library"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kadet1090.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-25T21:28:32.000Z","updated_at":"2023-09-19T01:41:51.000Z","dependencies_parsed_at":"2022-08-21T12:10:51.460Z","dependency_job_id":null,"html_url":"https://github.com/kadet1090/nucleus","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kadet1090%2Fnucleus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kadet1090%2Fnucleus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kadet1090%2Fnucleus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kadet1090%2Fnucleus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kadet1090","download_url":"https://codeload.github.com/kadet1090/nucleus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103865,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jabber","php","php-7","xmpp-library"],"created_at":"2024-09-24T20:02:24.447Z","updated_at":"2025-04-09T20:04:04.127Z","avatar_url":"https://github.com/kadet1090.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Nucleus Logo](https://dl.dropboxusercontent.com/u/60020102/ShareX/2016-07/nucleus_Logo%20%2B%20Logotyp%20-%20Color.png)\n# [WiP] Nucleus - XMPP Library for PHP\n[![Packagist](https://img.shields.io/packagist/v/kadet/nucleus.svg?maxAge=2592000?style=flat-square)](https://packagist.org/packages/kadet/nucleus)\n![Milestone](https://img.shields.io/badge/milestone-2-yellow.svg)\n[![Travis](https://img.shields.io/travis/kadet1090/nucleus.svg?maxAge=2592000?style=flat-square)](https://travis-ci.org/kadet1090/nucleus)\n[![Scrutinizer](https://img.shields.io/scrutinizer/g/kadet1090/nucleus.svg?maxAge=2592000?style=flat-square)](https://scrutinizer-ci.com/g/kadet1090/nucleus/?branch=master)\n[![Code Climate](https://img.shields.io/codeclimate/github/kadet1090/nucleus.svg?maxAge=2592000)]()\n![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/kadet1090/nucleus.svg?maxAge=2592000?style=flat-square)\n\nAsynchronous XMPP library for PHP based on [React PHP](https://github.com/reactphp). Library is still work in progress,\nso I don't recommend using it. It obsoletes my old [`kadet/xmpp`](https://github.com/kadet1090/xmpp) package.\n\n## Already available\n### Modular Client class\nBy design client class (`\\Kadet\\Xmpp\\XmppClient`) acts like stream - for sending and receiving packets over network, \nevent emitter to inform about events, and dependency container (what a wonderful violation of SRP) for managing modules.\nIt allows to move almost all logic outside of that class into proper and exchangeable components.\n\nBasic client instance can be set up quite easily:\n```php\n$loop   = React\\EventLoop\\Factory::create();\n$client = new \\Kadet\\Xmpp\\XmppClient(new \\Kadet\\Xmpp\\Jid('local@domain.tld/resource'), [\n    'loop'     =\u003e $loop,\n    'password' =\u003e 'epicpasspeoem',\n]);\n\n// Event declatation ...\n\n$client-\u003econnect();\n$loop-\u003erun();\n```\n\nOptions passed to second argument, are equivalent to C#'s property instantiation, so above example is same as calling:\n```php\n$client = new \\Kadet\\Xmpp\\XmppClient(new \\Kadet\\Xmpp\\Jid('local@domain.tld/resource'));\n$client-\u003eloop = $loop;\n$client-\u003epassword = 'epicpasspoem';\n```\n\nWith exception for `modules` and `default-modules` which are used for initial module setup. You can disable default\nmodules by setting `default-modules` to false, but it's highly not recommended for non-test purposes.\n\nAvailable events are:\n```php\nelement(Kadet\\Xmpp\\Xml\\XmlElement $element) // element received\nfeatures(Kadet\\Xmpp\\StreamFeatures $features) // features received\n\nsend.element(Kadet\\Xmpp\\Xml\\XmlElement $element) // element sent\nsend.text(string $data) // some text (non valid XmlElement) sent\n\nstream.open(Kadet\\Xmpp\\Xml\\XmlElement $stream) // Stream started\nstream.close() // Stream closed\n\nstream.error(Kadet\\Xmpp\\Stream\\Error $error) // Stream errored\n\nconnect(StreamDuplexInterface $stream) // called when connection is ready\nexception(Exception $exception) // called when otherwise unhandled exception happens\n```\nalso, all default events from [`react/stream`] are applicable.\n\n#### TLS Handling\nMost of XMPP servers require TLS connection, by default React streams don't support encryption. Library will handle \nencryption if underlying stream implements `\\Kadet\\Xmpp\\Network\\SecureStream` interface (provided stream classes like \n`\\Kadet\\Xmpp\\Network\\TcpStream` implements it by default). \n\n### (Better)Event API\nNucleus uses extended version of [`evenement/evenement`] to provide convenient `EventEmitter` API. So you can now filter\nevents by predicates and event queue is prioritized. \n\n```php\n$emitter-\u003eon($event, $callback, $predicate = null, $priority = 0);\n```\n\nPredicate, as well as callback is called with arguments passed to event. There are few default predicates that you can\nuse, they can be found in [`Utils/Filter.php`](Utils/Filter.php).\n\n```php\n// Will fire event only if element belongs into self::TLS_NAMESPACE.\n$stream-\u003eon('element', $callable, with\\xmlns(self::TLS_NAMESPACE));\n```\n\nAlso you can prioritize events\n```php\n$stream-\u003eon('element', $second, null, 0);\n$stream-\u003eon('element', $first, null, 1); // will fire first\n```\n\nSender argument is not provided by default, if needed you have to partially apply function, there is also shortcut in\nevery event emitting class.\n```php\n$stream-\u003eon('element', $stream-\u003ereference($callable)); // Will fire $callable($stream, ...$arguments);\n```\n\nEvent queue can be stopped by returning `false` by event.\n\n## Things to do\nSee roadmap on [Trello], I'll keep it updated. Project is created in milestone system, it means that after completing\neach milestone API should be stable - but it's not guaranteed at the moment.\n\n\n[Trello]:  https://trello.com/b/WHQ6d3hw/xmpp\n[rfc6120]: xmpp.org/rfcs/rfc6120.html\n[`evenement/evenement`]: https://packagist.org/packages/evenement/evenement\n[`react/stream`]: https://github.com/reactphp/stream\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkadet1090%2Fnucleus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkadet1090%2Fnucleus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkadet1090%2Fnucleus/lists"}