Skip to content

attitude/phpx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPX is to PHP what JSX is to JS

Warning

Experimental project – give it a try

Turn PHPX syntax into PHP code

Source input:

<>
  <h1 className="title">Hello, {$name ?? ucfirst($type)}!</h1>
  <p>
    Welcome to the world of PHPX, where you can write PHP code in a JSX-like syntax.
    <img src="about:blank" alt="Happy coding!" /> forever!
  </p>
</>

Compiled output:

[
  ['$', 'h1', ['className'=>"title"], ['Hello, ', ($name ?? ucfirst($type)), '!']],
  ['$', 'p', null, [
    'Welcome to the world of PHPX, where you can write PHP code in a JSX-like syntax.',
    ['$', 'img', ['src'=>"about:blank", 'alt'=>"Happy coding!"]], ' forever!',
  ]],
]

Installation

Important

This project is not yet published to Packagist. You need to add the repository manually or clone the repository as a submodule.

Option 1: Add as a Git submodule

$ git submodule add [email protected]:attitude/phpx.git path/to/phpx

Option 2: Add as a dependency using Composer

Update composer.json of your project:

{
    ...,
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/attitude/phpx"
        }
    ],
    "require": {
        "attitude/phpx": "dev-main"
    }
}
$ composer install

Option 3: Download the repository as a ZIP


Usage

<?php

require_once 'path/to/phpx/src/Compiler.php';

$phpx = new \Attitude\PHPX\Compiler();

$phpx->compile(<<<'PHPX'
<>
  <h1 className="title">Hello, {$name ?? ucfirst($type)}!</h1>
  <p>
    Welcome to the world of PHPX, where you can write PHP code in a JSX-like syntax.
    <img src="about:blank" alt="Happy coding!" /> forever!
  </p>
</>
PHPX);

Enjoy!

Created by martin_adamko

Releases

No releases published

Packages

No packages published

Languages