Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/siguici/phun
PHP π Bun
https://github.com/siguici/phun
bun php phun
Last synced: about 1 month ago
JSON representation
PHP π Bun
- Host: GitHub
- URL: https://github.com/siguici/phun
- Owner: siguici
- License: mit
- Created: 2024-03-23T20:08:09.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-03-27T06:07:24.000Z (9 months ago)
- Last Synced: 2024-11-14T15:47:00.258Z (about 2 months ago)
- Topics: bun, php, phun
- Language: TypeScript
- Homepage: https://npmjs.com/package/phun
- Size: 22.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PHP π Bun (Phun)
Phun offers a seamless PHP integration for JavaScript/TypeScript projects, powered by Bun.
It's a great choice, especially if you prefer PHP over JSX/TSX.## π Requirements
Ensure you have the following installed:
- [**PHP**](https://www.php.net/downloads): Required for executing PHP code.
- [**Bun**](https://bun.sh/docs/installation): Needed for efficient PHP subprocess execution.
## β‘οΈInstallation
To install Phun, execute the following command with [Bun](https://bun.sh):
```shell
bun add phun
```## π§ Configuration
Configure Phun in your project by defining the files to import in [the Bun preload file](https://bun.sh/docs/runtime/bunfig#preload):
```typescript
import { setup } from "phun";setup();
```## π Usage
Phun provides multiple ways to incorporate PHP code into your JavaScript/TypeScript projects.### Rendering PHP Code
You can render PHP code directly using the `render()` function:
```typescript
import { render } from 'phun';const result = await render(`= "Hello, $name!" ?>`, { name: 'Sigui' });
console.log(result); // Output: Hello, Sigui!
```### Importing PHP Modules
You can import and use PHP modules in your JavaScript/TypeScript projects:
```typescript
import my_php_module from "my/php/module.php";console.log(my_php_module());
```### Dynamic Using with Data
You can pass data to PHP code for dynamic rendering using the `use()` function:
```typescript
import { use } from "phun";
const my_php_module = await use(import.meta.dir + '/my/php/module.php', { name: "Sigui", username: "siguici" });
console.log(my_php_module);
```## π Contributions
Contributions are welcome! You can:
- **Open Issues**: Report bugs or suggest improvements.
- **Submit Pull Requests**: Contribute bug fixes, new features, or documentation enhancements.
- **Provide Feedback**: Share your thoughts and ideas to help improve Phun.Let's collaborate and make Phun even more awesome together!
## π License
This project is licensed under the MIT License. [See the LICENSE file for more details](./LICENSE.md).