bear/ace

Ace online editor utility

1.0.1 2017-04-02 14:36 UTC

This package is auto-updated.

Last update: 2024-11-07 06:34:08 UTC


README

Ace online editor utility for PHP

BEAR.Ace is an Ace utility for PHP. (Ace is a standalone code editor written in JavaScript.) It enables you to use an editor via a web service or to fix syntax errors on the fly.

BEAR.AceはオンラインエディターAceのユーティリティです。 エディターwebサービスやシンタックスエラーのオンライン修正が可能です。

Latest Stable Version Build Status

Getting started

Installing via Composer

The recommended way to install BEAR.Ace is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

# Install as stand alone editor
php composer.phar create-project bear/ace BEAR.Ace

# Add BEAR.Ace as a dependency
php composer.phar require bear/ace:~1.0

Start the online editor web service

$ cd BEAR.Ace/web
$ php -S localhost:8090 index.php

You can now browse file content using the 'file' and 'line' (optional) query.

Editor

You can also save the file you are editing when you have write access to the web server. It supports save shortcut keys for Windows(Ctl+S) and OSX(Cmd+S).

Sample Code

Getting HTML to display in the editor.

$html = (string)(new Editor)->setRootPath($rootPath)->setPath($file)->setLine($line);

You can specify a $file as an absolute path or as a relative path from $rootPath. Files higher than $rootPath are not accessible for security reasons.

Starting the online service is simple using the following code.

try {
    $editor = (new Editor)->setRootPath($rootPath)->handle($_GET, $_POST, $_SERVER);
    echo $editor;
} catch (Exception $e) {
    http_response_code($e->getCode());
    echo $e->getCode();
}

More sample code can be found in the /docs/ directory.

Syntax Error Editor

Once an error handler has been registered, when a syntax error occurs, you can not only display the error but make a fix in the browser on the fly. The browser is then automatically reloaded for you upon save. This feature can really minimize the time and frustration caused by simple careless mistakes.

(new \BEAR\Ace\ErrorEditor)->registerSyntaxErrorEdit();

Editor

edit();

You can also view file content in the editor by using the edit function. Just specify the object or file path in the argument.

$file = __DIR__ . 'file.php';
edit($file);
$a = new A;
edit($a);

xdebug.file_link_format

The online editor can be linked to in the stack trace file name using the following ini configuration of xdebug.

xdebug.file_link_format=localhost:8090/?file=%f&line=$l

Syntax Error Integration in Symfony2

  1. Add "bear / ace" to composer.json, then install it with the composer command.
    "require": {
        ...
        "bear/ace": "*"
    },
$ composer update bear/ace
  1. Register a syntax error editor in web/app_dev.php.
require_once __DIR__.'/../app/AppKernel.php';
// after this line

(new \BEAR\Ace\ErrorEditor)->registerSyntaxErrorEdit();

// before this line
$kernel = new AppKernel('dev', true);
  1. That's it ! You can now fix syntax errors on the spot.

Requirements

  • PHP 5.3+