Code Monkey home page Code Monkey logo

pharcc's Introduction

pharcc

pharcc is a command-line tool that converts your php project into a single, executable .phar file for easy distribution.

Build Status Roadmap Items

Installation

pharcc requires php 5.3+. You must also set phar.readonly = Off in your php.ini or you will be unable to compile .phar files.

Via .phar

The easiest way to get it working is to download a tagged pharcc.phar release, and put this on your path. For example:

$ wget https://github.com/cbednarski/pharcc/releases/download/v0.2.3/pharcc.phar
$ chmod +x pharcc.phar
$ sudo mv pharcc.phar /usr/local/bin/pharcc

Other ways

Composer (thanks @clue):

$ composer global require cbednarski/pharcc=dev-master
$ echo 'export PATH=$PATH:$HOME/.composer/vendor/bin' >> ~/.bash_profile

From source:

$ git clone https://github.com/cbednarski/pharcc
$ cd pharcc
$ make install      # For using
$ make install-dev  # For hacking

Usage

pharcc is a command-line tool that examines your project and produces a .phar file. cd into your project root and run the following:

$ pharcc init
$ pharcc build

You can also use pharcc as a library and call the internals directly, but if you do that I'm going to assume you're comfortable reading the code yourself. It's pretty short. Comments are welcome!

How it works

A phar is essentially a slew of php files that are concatenated together to create a single, executable php file, complete with assets and such. pharcc reads a .pharcc.yml file from the root of your project and, combined with some assumed conventions, builds an executable phar for you.

I assume the following:

  • You're using a PSR-0 project structure (more below)
  • Your app is a console application

Based on our assumptions, I've selected some sensible defaults for which files to include or exclude from your .phar file, which you can customize by editing the .pharcc.yml file. If your application is not a console app, you can omit main from the config.

Your Project Layout

I assume your project layout looks something like this, which is pretty standard for PSR-0 applications:

.
├── LICENSE
├── bin
│   └── pharcc
├── composer.json
├── readme.md
├── src
│   └── cbednarski
│       └── Pharcc
├── tests
│   └── cbednarski
│       └── Pharcc
└── vendor
    ├── autoload.php
    ├── cbednarski
    │   └── fileutils
    ├── composer
    │   ├── ClassLoader.php
    └── symfony
        ├── console
        ├── finder
        └── yaml

If your application doesn't look like this pharcc will probably still work, but you'll need to tweak your .pharcc.yml with some other appropriate includes / excludes.

Version Reporting

If your project is in git, uses semver tags for releases, and uses the symfony console component, pharcc can report the version of your application on the commandline. For example:

$ pharcc --version
pharcc version 0.2.3

To make this work in your app, you'll need to add cbednarski\Pharcc\Git::getVersion(__DIR__) to your bin file.

use cbednarski\Pharcc\Git;

$application = new Symfony\Component\Console\Application('pharcc', Git::getVersion(__DIR__));

Note: The current implementation is pretty magic, and only works if you worship the git, semver, and symfony console component gods.

Contributing

Contributions are welcome! Please don't hesitate to file a bug, pull-request a feature, or let me know what could be made easier to use.

Check out the list of ready-for-dev items here: Roadmap Items Here are some guidelines to follow:

  • The spirit of this project is to be simple and solve the general use case of creating phar files. It currently supports console applications and I'm willing to accept pull requests to add the ability to make a web app phar, like the one for phpMyAdmin, and a self-update command. Other large features, maybe. Get in touch.
  • If you file a bug please include steps to repro, or even better, link me to a git hash that's failing to compile properly (make sure it includes your .pharcc.yml file).
  • Code follows PSR-2 formatting rules. Use php-cs-fixer to reformat your code before you PR.
  • Use phpunit to run the unit tests and make sure they pass.
  • Please add tests if you add a feature or fix a bug.

pharcc's People

Contributors

andrejpavlovic avatar cbednarski avatar clue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

cursesun

pharcc's Issues

broken app

does not work out of the box, following instructions. no one maintains this repo?

I gave up after an hour of trying to fix things/get thing to work. At:
use cbednarski\FileUtils\FileUtils; - there is no such file. and as such the class does not exist. as such the code breaks. (found the file inside vendor.
funny enough, "use cbednarski\Pharcc\Git;" also points to the same location. except, it does not exist there either.

examples of code that use the class:
$files = array_merge($files, FileUtils::listFilesInDir(
$relative_path = (FileUtils::pathDiff($this->config->getBasePath(), $file, true));
$this->phar->addFromString(FileUtils::pathDiff($this->config->getBasePath(), $file, true), $content);

after this is fixed, who knows what is broken next?

the namespace and include files are all messed up.
my version is 0.2.4

Stable release with stable dependencies

To be able to use this project as a require-dev dependency using composer, it not only needs to be stable but also needs stable dependencies.

Is it possible to somehow get this fixed?

Add auto-update functionality

This can be accomplished by using the github API but it may be subject to rate limiting. Some data:

Download URLs:

Json response from releases API
(GET https://api.github.com/repos/cbednarski/pharcc/releases):

[
  {
    "id" : 122453,
    "body" : "- Updated fileutils dependency to a tagged version for composer stable release\r\n- Fixed reference to `Exception` rather than `\\Exception`\r\n- Improved error messaging when phar.readonly is set in `php.ini`\r\n- Improved error messaging when there is an errant include in `pharcc.yml`",
    "name" : "",
    "published_at" : "2013-12-15T12:14:39Z",
    "prerelease" : true,
    "assets" : [
      {
        "content_type" : "application/octet-stream",
        "state" : "uploaded",
        "id" : 49109,
        "download_count" : 0,
        "created_at" : "2013-12-15T12:11:40Z",
        "size" : 484598,
        "label" : "pharcc.phar",
        "updated_at" : "2013-12-15T12:14:39Z",
        "name" : "pharcc.phar",
        "url" : "https://api.github.com/repos/cbednarski/pharcc/releases/assets/49109"
      }
    ],
    "created_at" : "2013-12-15T12:10:12Z",
    "zipball_url" : "https://api.github.com/repos/cbednarski/pharcc/zipball/v0.2.3",
    "url" : "https://api.github.com/repos/cbednarski/pharcc/releases/122453",
    "target_commitish" : "master",
    "tarball_url" : "https://api.github.com/repos/cbednarski/pharcc/tarball/v0.2.3",
    "html_url" : "https://github.com/cbednarski/pharcc/releases/v0.2.3",
    "assets_url" : "https://api.github.com/repos/cbednarski/pharcc/releases/122453/assets",
    "tag_name" : "v0.2.3",
    "upload_url" : "https://uploads.github.com/repos/cbednarski/pharcc/releases/122453/assets{?name}",
    "draft" : false
  },
  {
    "id" : 42365,
    "body" : "",
    "name" : "",
    "published_at" : "2013-09-11T03:31:15Z",
    "prerelease" : true,
    "assets" : [
      {
        "content_type" : "application/octet-stream",
        "state" : "uploaded",
        "id" : 17559,
        "download_count" : 5,
        "created_at" : "2013-09-11T03:31:04Z",
        "size" : 491561,
        "label" : "pharcc.phar",
        "updated_at" : "2013-09-11T03:31:15Z",
        "name" : "pharcc.phar",
        "url" : "https://api.github.com/repos/cbednarski/pharcc/releases/assets/17559"
      }
    ],
    "created_at" : "2013-09-11T03:26:08Z",
    "zipball_url" : "https://api.github.com/repos/cbednarski/pharcc/zipball/v0.2.1",
    "url" : "https://api.github.com/repos/cbednarski/pharcc/releases/42365",
    "target_commitish" : "master",
    "tarball_url" : "https://api.github.com/repos/cbednarski/pharcc/tarball/v0.2.1",
    "html_url" : "https://github.com/cbednarski/pharcc/releases/v0.2.1",
    "assets_url" : "https://api.github.com/repos/cbednarski/pharcc/releases/42365/assets",
    "tag_name" : "v0.2.1",
    "upload_url" : "https://uploads.github.com/repos/cbednarski/pharcc/releases/42365/assets{?name}",
    "draft" : false
  }
]

when building, getting this error

Fatal error: Class 'cbednarski\Pharcc\Exception' not found in phar://C:/homes/jarda_p/bin/pharcc.phar/src/cbednarski/Pharcc/Compiler.php on line 114

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.