Move files one level up

Summary: Diff created by running `kill_init.php`, moving `xhpast_parse.php` back to `bin/`, liberating and manually changing paths to 'data/' in tests.

Test Plan:
##arc unit `find . -name __tests__`##
Load Phabricator homepage.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Maniphest Tasks: T1103

Differential Revision: https://secure.phabricator.com/D2635
Remove unused variable
Improve parsing for email addresses like: alincoln <alincoln at logcabin dot com>

Summary: There are some of these in the Mercurial repository commit log. Handle them more gracefully, without raising warnings.

Test Plan: Ran unit tests.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2592
Fix comment
Fix comment
Convert E_RECOVERABLE_ERROR into RuntimeException

Summary:
We currently treat typehint violations as warnings in normal use, and only raise InvalidArgumentException via assert_instances_of(). Instead, always raise InvalidArgumentException.

E_RECOVERABLE_ERRORs are always severe; raise them all as runtime errors.

Raise "use of undefined variable" as a runtime error, it is highly correlated with badness.

Test Plan: Ran a program with undefined variables and typehint problems.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D2653
Handle errors in history-enabled prompt

Test Plan: Ran on supported environment - still works.

Reviewers: csilvers

Reviewed By: csilvers

CC: aran, epriestley

Maniphest Tasks: T1302

Differential Revision: https://secure.phabricator.com/D2633
Be less aggressive in kill_init.php

Test Plan: Run it.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2667
Add stub for PhutilSymbolLoader::loadClass()

Summary: We need some time to transition (stale working copies and such).

Test Plan: `arc lint` on v1 library using this.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2666
Micro-optimize idx()

Summary:
Do we call this function often enough to justify some speed tricks?

Tested in Zend PHP 5.4 (median of 3 runs):

  idx($array, 'present'); // 36% faster
  idx($array, 'missing'); // 23% faster
  idx($array, 'missing', false); // 21% slower

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2672
PhutilChannel, a stream/pipe I/O wrapper

Summary:
I'm in the process of implementing a Mercurial daemon which uses "hg serve --cmdserver" to improve the performance of Mercurial operations.

The rough design of this server is a proxy server that speaks the cmdserver protocol, opens an hg server on one end (via normal pipes), and listens to multiple clients on the other end (a unix domain socket).

We don't have many PHP servers right now, so we're a little weak on abstractions. This is probably a bit over-engineered, but this server has two different components which speak the same protocol but have different underlying transports:

  - The client speaks to a (proxied) cmdserver over a unix domain socket.
  - The server speaks to a (real) cmdserver over a pipe.

So separating "how to speak to a cmdserver" from "how to do I/O" seemed to make sense.

Test Plan: Implemented an actual server on top of this, see next diff.

Reviewers: csilvers, btrahan, vrana

Reviewed By: csilvers

CC: aran

Differential Revision: https://secure.phabricator.com/D2663
Fix waitForMessage() to always throw when the connection is closed

Summary: See D2663. Currently, this method sometimes returns implicit null and sometimes throws on a closed connection. Make it always throw.

Test Plan: Reasoned about program behavior.

Reviewers: csilvers

Reviewed By: csilvers

CC: aran

Differential Revision: https://secure.phabricator.com/D2676
Fix lint errors found by Nemo

Test Plan: Ran a script analyzing sources by HPHP.

Reviewers: epriestley, jungejason

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2712
Fix lint error
Introduce translator

Summary:
This allows simple `sprintf()`-like translations with support for selecting variants based on numbers.

It can be fairly easily extended to support other variants (e.g. based on sex).

Test Plan: New tests.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1139

Differential Revision: https://secure.phabricator.com/D2744
Support male/female variations in translations

Test Plan: `arc unit`

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1139

Differential Revision: https://secure.phabricator.com/D2755
Allow setting instance of PhutilTranslator

Summary:
I will need it for sending e-mails. The plan is this:

- Set instance to recipient's language (or server default if multiplexing is disabled).
- Build e-mails.
- Set it back.

The other option would be to give up on using `pht()` and inject `$translator` everywhere and use it instead but it seems too complex even if it would be cleaner.

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1139

Differential Revision: https://secure.phabricator.com/D2772
Follow redirects in HTTPSFuture and add a simple wrapper function above it

Summary: See D2787 for usage.

Test Plan:
  echo strlen(HTTPSFuture::loadContent('http://vrana.cz/'))."\n"; // redirect
  echo strlen(HTTPSFuture::loadContent('http://www.vrana.cz/'))."\n";
  echo strlen(HTTPSFuture::loadContent('http://www.vrana.czzz/'))."\n";

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2785
Categorize internationalization docs

Test Plan: `diviner .`

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2790
Add a "verbose" mode to daemons for activity logging

Summary: See discussion in T1389. Some daemon issues are pretty painful to troubleshoot over IRC, add a log() method activated by a --verbose flag to allow conditional activity logging at a more useful level than "errors only" (which isn't verbose enough) or "--trace" (which is far too verbose).

Test Plan: Ran "nice" daemon in verbose and non-verbose modes.

Reviewers: vrana, jungejason, edward, aurelijus

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1389

Differential Revision: https://secure.phabricator.com/D2795