{ "info": { "author": "Jan Verbeek", "author_email": "jan.verbeek@posteo.nl", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: ISC License (ISCL)", "Programming Language :: PHP", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3 :: Only" ], "description": "This is a Python module for running PHP programs. It lets you import PHP functions, classes, objects, constants and variables to work just like regular Python versions.\n\n# Examples\n\nYou can call functions:\n```\n>>> from phpbridge import php\n>>> php.array_reverse(['foo', 'bar', 'baz'])\nArray.list(['baz', 'bar', 'foo'])\n>>> php.echo(\"foo\\n\")\nfoo\n>>> php.getimagesize(\"http://php.net/images/logos/new-php-logo.png\")\nArray([('0', 200), ('1', 106), ('2', 3), ('3', 'width=\"200\" height=\"106\"'), ('bits', 8), ('mime', 'image/png')])\n```\n\nYou can create and use objects:\n```\n>>> php.DateTime\n\n>>> date = php.DateTime()\n>>> print(date)\n\n>>> date.getOffset()\n7200\n>>> php.ArrayAccess\n\n>>> issubclass(php.ArrayObject, php.ArrayAccess)\nTrue\n```\n\nYou can use keyword arguments, even though PHP doesn't support them:\n```\n>>> date.setDate(year=1900, day=20, month=10)\n\n```\n\nYou can loop over iterators and traversables:\n```\n>>> for path, file in php.RecursiveIteratorIterator(php.RecursiveDirectoryIterator('.git/logs')):\n... print(\"{}: {}\".format(path, file.getSize()))\n...\n.git/logs/.: 16\n.git/logs/..: 144\n.git/logs/HEAD: 2461\n[...]\n```\n\nYou can get help:\n```\n>>> help(php.echo)\nHelp on function echo:\n\necho(arg1, *rest)\n Output one or more strings.\n\n @param mixed $arg1\n @param mixed ...$rest\n\n @return void\n```\n\nYou can import namespaces as modules:\n```\n>>> from phpbridge.php.blyxxyz.PythonServer import NonFunctionProxy\n>>> help(NonFunctionProxy)\nHelp on class blyxxyz\\PythonServer\\NonFunctionProxy in module phpbridge.php.blyxxyz.PythonServer:\n\nclass blyxxyz\\PythonServer\\NonFunctionProxy(phpbridge.objects.PHPObject)\n | Provide function-like language constructs as static methods.\n |\n | `isset` and `empty` are not provided because it's impossible for a real\n | function to check whether its argument is defined.\n |\n | Method resolution order:\n | blyxxyz\\PythonServer\\NonFunctionProxy\n | phpbridge.objects.PHPObject\n | builtins.object\n |\n | Class methods defined here:\n |\n | array(val) -> dict from phpbridge.objects.PHPClass\n | Cast a value to an array.\n |\n | @param mixed $val\n |\n | @return array\n[...]\n```\n\nYou can index, and get lengths:\n```\n>>> arr = php.ArrayObject(['foo', 'bar', 'baz'])\n>>> arr[10] = 'foobar'\n>>> len(arr)\n4\n```\n\nYou can work with PHP's exceptions:\n```\n>>> try:\n... php.get_resource_type(3)\n... except php.TypeError as e:\n... print(e.getMessage())\n...\nget_resource_type() expects parameter 1 to be resource, integer given\n```\n\n# Features\n * Using PHP functions\n * Keyword arguments are supported and translated based on the signature\n * Docblocks are also converted, so `help` is informative\n * Using PHP classes like Python classes\n * Methods and constants are defined right away based on the PHP class\n * Docblocks are treated like docstrings, so `help` works and is informative\n * The original inheritance structure is copied\n * Default properties become Python properties with documentation\n * Other properties are accessed on the fly as a fallback for attribute access\n * Creating and using objects\n * Importing namespaces as modules\n * Getting and setting constants\n * Getting and setting global variables\n * Translating exceptions so they can be treated as both Python exceptions and PHP objects\n * Tab completion in the interpreter\n * Python-like reprs for PHP objects, with information like var_dump in a more compact form\n\n# Caveats\n * On Windows, stdin and stderr are used to communicate, so PHP can't read input and if it writes to stderr the connection is lost\n * You can only pass basic Python objects into PHP\n * Namespaces can shadow names in an unintuitive way\n * Because PHP only has one kind of array, its arrays are translated to a special kind of ordered dictionary\n\n# Name conflicts\nSome PHP packages use the same name both for a class and a namespace. As an example, take `nikic/PHP-Parser`.\n\n`PhpParser\\Node` is a class, but `PhpParser\\Node\\Param` is also a class. This means `phpbridge.php.PhpParser.Node` becomes ambiguous - it could either refer to the `Node` class, or the namespace of the `Param` class.\n\nIn case of such a conflict, the class is preferred over the namespace. To get `Param`, a `from` import has to be used:\n```\n>>> php.require('vendor/autoload.php')\n\n>>> import phpbridge.php.PhpParser.Node as Node # Not the namespace!\n>>> Node\n\n>>> from phpbridge.php.PhpParser.Node import Param # The class we want\n>>> Param\n\n>>> import phpbridge.php.PhpParser.Node.Param as Param # Doesn't work\nTraceback (most recent call last):\n File \"\", line 1, in \nAttributeError: type object 'PhpParser\\Node' has no attribute 'Param'\n```\n\nIf there are no conflicts, things work as expected:\n```\n>>> from phpbridge.php.blyxxyz.PythonServer import Commands\n>>> Commands\n\n>>> import phpbridge.php.blyxxyz.PythonServer as PythonServer\n>>> PythonServer\n\n>>> PythonServer.Commands\n\n```\n\n# Installing\nThe only dependencies are PHP 7.0+, Python 3.5+, ext-json and ext-reflection. Composer can be used to install development tools and set up autoloading, but it's not required.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/blyxxyz/Python-PHP-Bridge", "keywords": "", "license": "ISC", "maintainer": "", "maintainer_email": "", "name": "phpbridge", "package_url": "https://pypi.org/project/phpbridge/", "platform": "", "project_url": "https://pypi.org/project/phpbridge/", "project_urls": { "Homepage": "https://github.com/blyxxyz/Python-PHP-Bridge" }, "release_url": "https://pypi.org/project/phpbridge/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "Import PHP code into Python", "version": "0.0.3" }, "last_serial": 4544054, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "5a1859befbaf4bd98c33c5e64d31cd1d", "sha256": "832d7cb19a2cca48ff356cc1ea9fb43396630de326416759f546a22dcd95ad1b" }, "downloads": -1, "filename": "phpbridge-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5a1859befbaf4bd98c33c5e64d31cd1d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21986, "upload_time": "2018-11-29T18:44:17", "url": "https://files.pythonhosted.org/packages/f1/3c/09835fde29c4963ee68d4e587e78af0b213f0cff1ede61f857c8f8dc3fa4/phpbridge-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "08158058ad84be429a1e6d33f2150161", "sha256": "0f6fb838a82fc241c5c268c10672252b8fd6a885a90bc1a09f70e4fb051ab5ed" }, "downloads": -1, "filename": "phpbridge-0.0.1.tar.gz", "has_sig": false, "md5_digest": "08158058ad84be429a1e6d33f2150161", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15893, "upload_time": "2018-11-29T18:44:19", "url": "https://files.pythonhosted.org/packages/07/cf/a56ee3bda7753a65f5492f63d56a03164d40da82081f4330fc19a9cd2ec7/phpbridge-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "0460aef0d5b01f988a79b2388fc59102", "sha256": "1291cfcbb31c56758929bb58b2c6ba05cf28314a6a0c2ef8f2270c521a63e175" }, "downloads": -1, "filename": "phpbridge-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "0460aef0d5b01f988a79b2388fc59102", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 30882, "upload_time": "2018-11-29T18:59:42", "url": "https://files.pythonhosted.org/packages/fe/88/df26a7ee4ff6c31f57cc86e157772f1c39cb35c4cfc57f18b9c2d4268144/phpbridge-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a7cb4514689d0a1a7c889bbcc8182db5", "sha256": "f0563652d03918de8eb99f8a9890e01e160379160112909687aaf345aff7b2ea" }, "downloads": -1, "filename": "phpbridge-0.0.2.tar.gz", "has_sig": false, "md5_digest": "a7cb4514689d0a1a7c889bbcc8182db5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22579, "upload_time": "2018-11-29T18:59:44", "url": "https://files.pythonhosted.org/packages/58/29/2ba9f321b742bff86525ea6ba46c0cdaa08956f4f65b7264e597c7d0691d/phpbridge-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "f7415f39daa4ccb77500308165f07dc6", "sha256": "455550a6bbbfde20eadf2737ff3b7f725965ccd72e8fbd63ba0e1d8d5c63464c" }, "downloads": -1, "filename": "phpbridge-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "f7415f39daa4ccb77500308165f07dc6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 35840, "upload_time": "2018-11-29T19:06:58", "url": "https://files.pythonhosted.org/packages/70/9e/e83cd2746343fe848c21c7da3db551d4adeee142648022caeecde0f5985b/phpbridge-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aa3c5717de2b172a1676184e1fd28176", "sha256": "3970deddd690c79076990aa5388f210d004fcfda7c1d401e2a09ff98d0b1d5b6" }, "downloads": -1, "filename": "phpbridge-0.0.3.tar.gz", "has_sig": false, "md5_digest": "aa3c5717de2b172a1676184e1fd28176", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25364, "upload_time": "2018-11-29T19:07:00", "url": "https://files.pythonhosted.org/packages/1d/da/1437d867296ac84a756511102b4a01474d324286fff090ceb38e1da79988/phpbridge-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f7415f39daa4ccb77500308165f07dc6", "sha256": "455550a6bbbfde20eadf2737ff3b7f725965ccd72e8fbd63ba0e1d8d5c63464c" }, "downloads": -1, "filename": "phpbridge-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "f7415f39daa4ccb77500308165f07dc6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 35840, "upload_time": "2018-11-29T19:06:58", "url": "https://files.pythonhosted.org/packages/70/9e/e83cd2746343fe848c21c7da3db551d4adeee142648022caeecde0f5985b/phpbridge-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aa3c5717de2b172a1676184e1fd28176", "sha256": "3970deddd690c79076990aa5388f210d004fcfda7c1d401e2a09ff98d0b1d5b6" }, "downloads": -1, "filename": "phpbridge-0.0.3.tar.gz", "has_sig": false, "md5_digest": "aa3c5717de2b172a1676184e1fd28176", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25364, "upload_time": "2018-11-29T19:07:00", "url": "https://files.pythonhosted.org/packages/1d/da/1437d867296ac84a756511102b4a01474d324286fff090ceb38e1da79988/phpbridge-0.0.3.tar.gz" } ] }