I'm trying to create a single-file version of PHP framework Nette 2.4. I create a phar file using this code:
<?php
$phar = new Phar('nette.phar');
$phar->buildFromDirectory(__DIR__ . '/../vendor/nette');
$phar->setStub("<?php
require 'phar://' . __FILE__ . '/loader.php';
__HALT_COMPILER();");
$phar->compressFiles(Phar::GZ);
Everything is fine, the file is created. If I try to use this compacted version:
// bootstrap.php
<?php
require __DIR__ . '/nette.phar';
...
Error occurs:
Warning: require(phar://C:\wamp64\www\app\nette.phar/loader.php): failed to open stream: phar error: "loader.php" is not a file in phar "C:/wamp64/www/app/nette.phar" in C:\wamp64\www\app\nette.phar on line 2
So, single-file version is loaded, but there is no boot file loader.php. Does anyone know where is the mistake? Thanks for all the suggestions!
You can't create .phar from Nette downloaded via Composer. It doesn't have some necessary files (e.g. your Loader.php).
If you want to create .phar download official .zip from https://nette.org/en/download and create .phar from folder ./Nette.
__
BTW you don't need to create .phar yourself, you can find it in the .zip file in folder Nette-minified
I'm just getting back into PHP and trying to do things the correct way from the beginning. So I've installed PHPLint 2.1_20151116 and I cannot seem to get it to work with composer's autoload. Is it possible?
For example I am trying to add a test case to Laravel/Envoy, but I cannot get past an error "undeclared parent class TestCase".
The folder structure is:
envoy
├── tests
│ ├── RemoteProcessorTest.php
│ ├── SSHConfigFileTest.php
│ └── TestCase.php
The contents of RemoteProcessorTest.php is:
<?php
namespace Laravel\Envoy;
class RemoteProcessTest extends TestCase
{
}
If I run ./vendor/bin/phpunit then I get the error: No tests found in class "Laravel\Envoy\RemoteProcessTest".. Which isn't a syntax error so it looks like everything is valid. But phplint still complains.
$ cd envoy
$ phpl --php-version 5 --print-path relative --print-column-number --tab-size 4 --no-overall tests/RemoteProcessorTest.php
BEGIN parsing of tests/RemoteProcessorTest.php
1: <?php
2: namespace Laravel\Envoy;
3:
4: class RemoteProcessTest extends TestCase
5: {
{
\_ HERE
==== 5:1: ERROR: undeclared parent class TestCase
6: }
END parsing of tests/RemoteProcessorTest.php
Is there a work around for this?
I may not be able to answer the question directly as the repo in question seems too limited to give you what you seek. I'll leave it to the community to answer the question directly.
Here are some alternatives that hopefully will help.
If you want to syntax check PHP has a built-in linter. Simply:
$ php -l filename.php
or --syntax-check instead of -l.
There is also this on packagist as a viable alternative. https://packagist.org/packages/gamegos/php-code-sniffer
It has a configuration file named phpcs.xml that you can check into your repo and include via composer.
# composer.json
...
require-dev {
"gamegos/php-code-sniffer": "0.4.0"
}
...
The phpcs.xml file has a bootstrap tag that will give it the information to find the Laravel classes among your own.
<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
<rule ref="Gamegos" />
<arg name="bootstrap" value="vendor/autoload.php" />
</ruleset>
After installing with Composer you'll have 3 binaries:
vendor/bin/phpcbf
vendor/bin/phpcs
vendor/bin/phpcs-pre-commit
You can find a lot of customization options on the Github repo. https://github.com/gamegos/php-code-sniffer
I am having some trouble configuring doctrine orm on windows 8, php 5.4. I have installed Doctrine using Composer.
I have followed the docs to the letter but when I run any commands, php vendor/bin/doctrine orm:schema-tool:create for example, my command line just outputs
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../doctrine/orm/bin"
BIN_TARGET="`pwd`/doctrine"
cd "$SRC_DIR"
"$BIN_TARGET" "$#"
I have also tried php vendor/bin/doctrine.php .... but it just prints out the above.
I have followed Doctrine's guide to the letter. Has anyone seen this before and if so, can you suggest anything?
i found a solution
there are also a bin folder in vendor/doctrine/orm/bin/ you can use this one like this
php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
make sure you have root folder and a cli-config.php file is present in root folder.
below is location where i found a solution
https://groups.google.com/forum/#!msg/doctrine-user/_ph183Kh-5o/_P_coljB-dcJ
this is working fine for me .
I had the same problem. The following solution worked for me:
"vendor/bin/doctrine.bat" orm:schema-tool:create
So, basically you:
use the ".bat" file provided by Doctrine and
enclose the call to that ".bat" file in quotes.
My Environment
Windows 7 Professional (x64)
PHP 5.5.12
Doctrine ORM 2.4.4
Do not write "php..." (it will write the file content)
Just "vendor\bin\doctrine orm:schema-tool:create" do the job (from the project root eg. c:\php\theProject).
Next, you will need a "cli-config.php" in the project root...
For Window version use backward slash "\"
vendor\bin\doctrine orm:schema-tool:create
not forward slash "/"
vendor/bin/doctrine orm:schema-tool:create
You can either install something like git bash or simply use the PHP version of the script:
php vendor\bin\doctrine.php orm:info
Obviously, the php binary directory should be in your PATH environment variable, otherwise, it's something like:
C:\path\to\php.exe vendor\bin\doctrine.php orm:info
Copy doctrine.bat (located at vendor/bin/doctrine.bat) to your project root directory
Create a bootstrap.php file in any path inside your project root directory with the following content:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array("../model");
$isDevMode = false;
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'root',
'password' => '',
'dbname' => 'angular_php',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
Create a cli-config.php file in your project root directory with the following content:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'path/to/file/bootstrap.php';
return ConsoleRunner::createHelperSet($entityManager);
Execute from a command line window (CMD):
c:\path\to\project\root\directory>doctrine --help
It's done!
I found it wasnt returning anything from the doctrine.php.bat. Turns out it was a PHP error in my cli-config.php file
Using Cygwin on Windows with doctrine installed via composer, was having the same problem
resolved by:
vendor/bin/doctrine.bat orm:convert-mapping
if you are still having issues you can run the cli script using php to get the console tools running:
for example
php cli-config.php orm:schema-tool:create
All the answers on this question are either outdated or outright incorrect. In my case, I observed, after installing the the library, the "\vendor\doctrine\orm\" folder was completely empty. The docs ask you to run vendor/bin/doctrine, which in turn attempts to call "vendor\doctrine\orm\bin\doctrine[.php]" (The php file extension is optional). After discovering this, I downloaded the library from the git repository and replaced the composer-installed version.
php vendor/doctrine/orm/bin/doctrine
then works fine.
Also, beware of the common misconception that the cli-config.php file must exist in the root of your project. It's fine to leave it in your config folder
I started working on yii framework in last 2-3 days....
i am trying to follow this tutorial simple mailer ....
After copying the files into extension folder and after writing these lines into configuration file, when I openned the index page of my test application, it gives me the following exception:
throw new CException(Yii::t('yii','Object configuration must be an array containing a "class" element.'));
and below is the screenshot of stacktrace:
Can anyone help me out here?
after copying the files into extension folder
You have to copy simplemailer into modules directory '/protected/modules/...
cp modules/SimpleMailer/commands/MailerCommand.php commands/
Execute installations:
http://www.yiiframework.com/extension/simplemailer#hh6
cd /your/app/directory/protected
./yiic migrate create add_simplemailer_tables
--templateFile=application.modules.SimpleMailer.migrations.template
./yiic migrate up
cp modules/SimpleMailer/commands/MailerCommand.php commands/
I'm trying to create a very simple PHP CLI application that can be run as a phar file from the command line:
# php myProject.phar
This is what I've tried so far:
My Project
My project is in a directory called MyProject and it has these two files in it:
|-- createPhar.php
`-- bootstrap.php
bootstrap.php
The bootstrap.php file contains this:
<?php
print phpversion() . PHP_EOL;
print 'i am some script' . PHP_EOL;
When I run this script from my Ubuntu command line:
# cd MyProject
# php bootstrap.php
I get the following output:
5.3.2-1ubuntu4.9
i am some script
createPhar.php
The createPhar.php file is meant to turn the project into Phar archive.
It looks like this:
<?php
$phar = new Phar('MyProject.phar');
$phar->addFile('bootstrap.php');
$phar->setStub( $phar->createDefaultStub('bootstrap.php') );
When I run that script...
# php createPhar.php
... a new file called MyProject.phar is created in my project's directory.
|-- bootstrap.php
|-- createPhar.php
`-- MyProject.phar
Now here's the problem
When I run the phar file...
# php MyProject.phar
...I expect to see the same the same output that I got when when I ran the bootstrap.php script.
Instead I see nothing. No output at all. This implies that my bootstrap.php script is not being included by the default stub that was created by $phar->createDefaultStub('bootstrap.php')
I think I am misunderstanding how Phars and their stubs are being created. Could you, please, explain where I have gone wrong.
To answer my own question.
The method outlined in my question, above, is one correct way to create a phar / phar stub.
The reason why it did not work for me and did work for Mario (see his comment below the question), is because I had Suhosin installed and needed to tweak the settings.
Fixed using the technique outlined here:
To fix, put:
suhosin.executor.include.whitelist="phar"
in /etc/php5/cli/php.ini
you could also do it like this:
bootstrap.php;
<?php
function go() {
print phpversion() . PHP_EOL;
print 'i am some script' . PHP_EOL;
}
then:
php -r "require
'phar://Myproject.phar'; go();"
or don't have a function and it will execute whatever commands you have in there, but typically you would have some functions or class files in the phar.