Doctrine 2 Command line print Cygwin configuration - php

I am trying to use Doctrine 2 in my project, but when I try to access the command line to import the Entities from my database to generate the files, it print the code from vendor/bin/doctrine
dir=$(d=${0%[/\\]*}; cd "$d"; cd '../doctrine/orm/bin' && pwd)
# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m $dir);
fi
fi
dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/doctrine.php" "$#"
My folder structure:
src/
vendor/
bootstrap.php
cli-config.php
composer.json
composer.lock
index.php
bootstrap.php
<?php
require_once "vendor/autoload.php";
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array("src/Entity");
$isDevMode = false;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => '',
'password' => '',
'dbname' => '',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
cli-config.php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
I am trying to use in my command line: php vendor/bin/doctrine --help. I am using also Vagrant with Ubuntu 14.01.
I am not using Symfony 2, Just trying to install Doctrine without any framework.
Thank you.

I got the same error when I was in windows setup and this command worked to resolve it:
php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create
Source:
http://www.agevaled.com/2013/10/09/doctrine2-getting-started-issues/2147483647/

On Windows, the correct command to run is:
vendor/bin/doctrine.bat

Related

grumphp not working correclty with custom directory structure

For some reason grumphp not working for me as expected.
First of all my project directory structure is:
.git/
devops/
app/
src/
confing/
bin/
vendor/
grumphp.yml
phpcs.xml
...
so I in the git repo I have some docker related files in the devops folder, and symfony app int the app folder, also in app folder I have grumphp and all linters configs.
I want to run grumphp from inside of the docker container when I commit some changes to check if my code is correct.
Here is my grumphp.yml
grumphp:
environment:
variables:
GRUMPHP_PROJECT_DIR: "."
GRUMPHP_GIT_WORKING_DIR: "../"
GRUMPHP_BIN_DIR: "vendor/bin/"
GRUMPHP_GIT_REPOSITORY_DIR: "../.git/"
git_hook_variables:
EXEC_GRUMPHP_COMMAND: docker exec php-fpm
stop_on_failure: false
ignore_unstaged_changes: false
hide_circumvention_tip: false
process_timeout: 6
tasks:
composer: ~
phpcs:
standard: phpcs.xml
ignore_patterns: [./var/*, ./public/*, ./config/*, ./bin/*]
phpcsfixer2:
config: .php_cs
phpstan:
autoload_file: ./bin/.phpunit/phpunit-9.0.1-0/vendor/autoload.php
memory_limit: "-1"
git_commit_message:
allow_empty_message: false
enforce_capitalized_subject: false
enforce_no_subject_punctuations: false
enforce_no_subject_trailing_period: true
enforce_single_lined_subject: true
type_scope_conventions: []
max_body_width: 0
max_subject_width: 72
matchers:
Must contain JIRA issue number: /^(Merge)|([A-Z_0-9]+-[0-9]+)/
case_insensitive: true
multiline: true
additional_modifiers: ''
yamllint:
whitelist_patterns: [ ]
ignore_patterns:
- /^vendor\/(.*)/
object_support: false
exception_on_invalid_type: false
parse_constant: false
parse_custom_tags: false
testsuites:
pre-commit:
tasks:
- composer
- phpcs
- phpcsfixer2
- phpstan
- yamllint
- git_commit_message
and when I'm running vendor/bin/grumphp git:init from inside of the docker container, pre-commit file generated in the .git/hooks directory, generated pre-commit file content:
#!/bin/sh
#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#
# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false -c diff.noprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
# Grumphp env vars
export GRUMPHP_GIT_WORKING_DIR="$(git rev-parse --show-toplevel)"
# Run GrumPHP
(cd "app/" && printf "%s\n" "${DIFF}" | docker exec php-fpm 'vendor/phpro/grumphp/bin/grumphp' 'git:pre-commit' '--skip-success-output')
SO what is the issue?
When I run git commit having php files with a broken styles, grumphp telling that all is fine and allowing me to commit this files, but when I run vendor/bin/grumphp run from inside of the container all working fine and I see list of all the issues I need to fix.
So why all linters checks passing on commit when they should not, but when I'm running vendor/bin/grumphp run it's working as expected?
I'm not sure but I think it somehow related to my directory structure, I have .git in the root of repository, but symfony and grumphp.yml in the app directory.
Thanks in advance!

Continuous Integration and Development with Laravel

I'm new to Laravel, currently working on my first project. I have worked with CI before but never with Laravel. So, here's my deploy script for our Dev server. Not sure if this is the best approach. Anyway, the migrate part is giving me an error. After I get this to work I will try some php plugins to analyze code quality, duplication, unit tests, etc.
Please, see below
Script:
rsync -a . /var/www/html/dev/
cd /var/www/html/dev/
# cfg file for dev
cp .env.dev .env
# run composer
composer clearcache
composer install --optimize-autoloader
# optimize
php artisan cache:clear
php artisan optimize
php artisan route:cache | true
# migrate DB
php artisan migrate
Error:
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists:
Am I supposed to delete all my tables before doing the migration? If so, I don't see what's the useful part of using them for auto deployment. Besides, we have our tables filled with data for testing (manually filled as we don't want to auto seed).
You shouldn't delete all your tables before run migration.
This error come from your migrations table and your migrations at database\migrations folder have conflict.
You should resolve this conflict before return to continue configure Jenkins.
My suggestion:
You should use Rocketeer for control release versions of your projects.
You can share your .env file by shared folder.
You can run composer install and npm install by default configure of Rocketeer.
Here is my steps install and configure Rocketeer:
Install Rocketeer:
$ wget http://rocketeer.autopergamene.eu/versions/rocketeer.phar
$ chmod +x rocketeer.phar
$ mv rocketeer.phar /usr/local/bin/rocketeer
//TODO Install PHP for Jenkins server
$ sudo apt-get install php
//TODO Check rocketeer
$ rocketeer check
No connections have been set, please create one: (production) <~ Succeed
Setup remote server information
$ cd /var/lib/jenkins/drone-deploy/drone-deploy/server-dev
$ rocketeer ignite
No connections have been set, please create one: (production)develop
No host is set for [develop], please provide one:35.166.x.x
No username is set for [develop], please provide one:ec2-user
No password or SSH key is set for [develop], which would you use? (key) [key/password]key
Please enter the full path to your key (/var/lib/jenkins/.ssh/id_rs/var/lib/jenkins/.ssh/xxx.pem
If a keyphrase is required, provide it
No repository is set for [repository], please provide one:git#bitbucket.org:xx/xxxxxx.git
No username is set for [repository], please provide one:xxx
No password is set for [repository], please provide one:
develop/0 | Ignite (Creates Rocketeer's configuration)
What is your application's name ? (drone-php)drone_deploy
The Rocketeer configuration was created at server-dev/.rocketeer
Configure
$ cd /var/lib/jenkins/drone-deploy/drone-deploy/drone-php
$ nano .rocketeer/config.php
Replace connections name production --> develop //It's Rocketeer bug
$ nano .rocketeer/remote.php
'root_directory' => '/var/www/html/',
'shared' => [
'storage/logs',
'storage/framework/sessions',
'.env',
],
'permissions' => [
// The folders and files to set as web writable
'files' => [
//'app/database/production.sqlite',
'bootstrap',
'storage',
'public',
],
// Here you can configure what actions will be executed to set
// permissions on the folder above. The Closure can return
// a single command as a string or an array of commands
'callback' => function ($task, $file) {
return [
sprintf('chmod -R 777 %s', $file),
sprintf('chmod -R g+s %s', $file),
sprintf('chown -R ec2-user:ec2-user %s', $file),
];
},
],
$ nano .rocketeer/strategies.php
//'test' => 'Phpunit',
'test' => '',
//return $composer->install([], ['--no-interaction' => null, '--no-dev' => null, '--prefer-dist' => null]);
return $composer->install([]);
Running test
rocketeer deploy --on="develop" --tests

nodejs cannot find module 'zombie' with PHP mink

I'm trying out Mink (PHP) on Ubuntu 14.04; I basically did the following:
$ apt-show-versions nodejs
nodejs:amd64/trusty 0.10.45-1nodesource1~trusty1 uptodate
$ npm -v
2.15.1
$ sudo npm install -g zombie
npm WARN engine zombie#4.2.1: wanted: {"node":"^4.0.0"} (current: {"node":"0.10.45","npm":"2.15.1"})
...
zombie#4.2.1 /usr/lib/node_modules/zombie
├── ms#0.7.1
├── debug#2.2.0
...
$ ls /usr/lib/node_modules/zombie/node_modules/
babel-runtime bluebird debug eventsource iconv-lite jsdom lodash mime ms request tough-cookie ws
So, basically, even if I get a warning, the modules build, and should be in the directory /usr/lib/node_modules.
Then I do:
mkdir test_php_mink
cd test_php_mink/
composer require behat/mink
composer require behat/mink-zombie-driver
As a check:
test_php_mink$ ls
composer.json composer.lock vendor
... it seems all composer files are there.
Finally, as per http://mink.behat.org/en/latest/drivers/zombie.html (and also Cannot find module 'zombie' · Issue #84 · assaf/zombie · GitHub), I'm trying this script:
<?php
# composer autoload:
require_once __DIR__ . '/vendor/autoload.php';
echo "safe_mode: '" . ini_get("safe_mode") ."'\n"; # have PHP 5.5.9, safe_mode is removed
putenv("NODE_PATH=/usr/lib/node_modules");
echo "NODE_PATH is: '" . getenv ( "NODE_PATH" ) . "'\n"; # OK, is there
# NOPE:
#$driver = new \Behat\Mink\Driver\ZombieDriver();
$driver = new \Behat\Mink\Driver\ZombieDriver(
new \Behat\Mink\Driver\NodeJS\Server\ZombieServer()
);
$session = new \Behat\Mink\Session($driver);
// start the session
$session->start();
?>
This script, unfortunately, still fails with:
$ php test_php_mink.php
safe_mode: ''
NODE_PATH is: '/usr/lib/node_modules'
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Server process has been terminated: (8) [
module.js:340
throw err;
^
Error: Cannot find module 'zombie'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/path/to/test_php_mink/vendor/behat/mink-zombie-driver/bin/mink-zombie-server.js:3:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
]' in /path/to/test_php_mink/vendor/behat/mink-zombie-driver/src/NodeJS/Server.php:413
Stack trace:
#0 /path/to/test_php_mink/vendor/behat/mink-zombie-driver/src/NodeJS/Server.php(306): Behat\Mink\Driv in /path/to/test_php_mink/vendor/behat/mink-zombie-driver/src/NodeJS/Server.php on line 413
How can I get this basic example to run?
EDIT: Played around a bit more with this, and discovered that when I specify the environment variable on the command line:
$ NODE_PATH=/usr/lib/node_modules php test_php_mink.php
safe_mode: ''
NODE_PATH is: '/usr/lib/node_modules'
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Server process has been terminated: (8) [
/usr/lib/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:238
var nonInheritedTags = new Set([
^
ReferenceError: Set is not defined
...
... then the module seems to be found! So my question basically reduces to: how can I change the NODE_PATH environment variable from my php script, so I wouldn't have to specify it on the shell - since apparently putenv("NODE_PATH=/usr/lib/node_modules"); does not really work for me...
As for the new error, there is Installing Zombie.js Error: ReferenceError: Set is not defined. What am I doing wrong? - apparently this is due to the version mismatch that I got a warning for (npm WARN engine zombie#4.2.1: wanted: {"node":"^4.0.0"} (current: {"node":"0.10.45","npm":"2.15.1"})), so I guess I'll have to install nvm so I can install the right nodejs version; and I also noticed in /usr/lib/node_modules/zombie/README.md:
Zombie 4.x is tested to work with io.js 1.6 or later.
If you need to use Node 0.12 or earlier, consider using Zombie 2.x. ...
To install Zombie.js you will need io.js:
```bash
$ npm install zombie --save-dev
```
... and I think that can also be installed with nvm; so I'll give that a try...
Ok, found some sort of a method which seemingly works - but I'd still like someone more knowledgeable to answer.
Anyways, the trick is - zombie can accept a path to the nodejs binary; so if you cannot really pass environment variables for nodejs from PHP, then make a shell script which will set these environment variables, and then call nodejs.
First this was my install:
# remove previous
sudo npm uninstall -g zombie --save-dev
sudo apt-get remove --purge nodejs && sudo apt-get autoremove --purge
# install new
curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
nvm install iojs-v3.3.1
npm list -g --depth=0
nvm install 4.0.0
npm list -g --depth=0
npm -g install zombie --save-dev
The problem with nvm is that it installs in a user directory, and I'd like to test my scripts both on my user machine and remote server, where my uids are completely different. Regardless, using a custom executable helps a bit with that. So, create a script in a "global" location, I chose /home, so I'll need sudo to create files there:
sudo touch /home/node_pth.sh
... then paste in the following content:
#!/bin/bash
export NODE_PATH=/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules
#echo ARGS ARE "$#" | tee -a /tmp/node.log
/home/USERNAME/.nvm/versions/node/v4.0.0/bin/node "$#"
... of course, replacing the paths with your correct ones; then finally make it executable:
sudo chmod +x /home/node_pth.sh
Now we can use the following test_php_mink.php PHP file:
<?php
$nodeModPath = "/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules"; # correct NODE_PATH, but will not help
$nodePath = "/home/node_pth.sh"; # shell script that sets NODE_PATH, then calls node executable
echo "NODE_PATH is: '" . getenv ( "NODE_PATH" ) . "'\n"; #
putenv("NODE_PATH=".$nodeModPath);
echo "NODE_PATH is: '" . getenv ( "NODE_PATH" ) . "'\n"; # is there - but still doesn't help with call
# composer autoload:
require_once __DIR__ . '/vendor/autoload.php';
echo "safe_mode: '" . ini_get("safe_mode") ."'\n"; # have PHP 5.5.9, safe_mode is removed
$driver = new \Behat\Mink\Driver\ZombieDriver(
//~ new \Behat\Mink\Driver\NodeJS\Server\ZombieServer()
# copy defaults here for everything but nodeBin;
# see vendor/behat/mink-zombie-driver/src/NodeJS/Server.php
new \Behat\Mink\Driver\NodeJS\Server\ZombieServer("127.0.0.1", 8124, $nodePath, null)
);
$session = new \Behat\Mink\Session($driver);
// start the session
$session->start();
?>
... OR, I just realized there is setNodeModulesPath($nodeModulesPath) in vendor/behat/mink-zombie-driver/src/NodeJS/Server.php, so we can drop the proxy bash executable altogether:
<?php
$nodeModPath = "/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules"; # correct NODE_PATH, but will not help via putenv
echo "NODE_PATH is: '" . getenv ( "NODE_PATH" ) . "'\n"; #
putenv("NODE_PATH=".$nodeModPath);
echo "NODE_PATH is: '" . getenv ( "NODE_PATH" ) . "'\n"; # is there - but still doesn't help with call
# composer autoload:
require_once __DIR__ . '/vendor/autoload.php';
echo "safe_mode: '" . ini_get("safe_mode") ."'\n"; # have PHP 5.5.9, safe_mode is removed
$zsrv = new \Behat\Mink\Driver\NodeJS\Server\ZombieServer();
$zsrv->setNodeModulesPath($nodeModPath . "/"); # needs to end with a trailing '/'
$driver = new \Behat\Mink\Driver\ZombieDriver( $zsrv );
$session = new \Behat\Mink\Session($driver);
// start the session
$session->start();
?>
Anyways, when this script is called, it outputs:
$ php test_php_mink.php
NODE_PATH is: ''
NODE_PATH is: '/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules'
safe_mode: ''
... and as there are no errors, I'm assuming it is all fine now...

How to generate data base with Doctrine 2?

I start with doctrine and want to create a db or php class from table with doctrine.
First i try create db. My bootstrap.php:
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
require_once "src/BugRepository.php";
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
$conn = array(
'driver' => 'pdo_pgsql',
'user' => 'postgres',
'password' => '123456',
'host' => 'localhost',
'dbname' =>'testdata',
);
$entityManager = EntityManager::create($conn, $config);
and i do:
php vendor/bin/doctrine doctrine:database:create
my output:
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../doctrine/orm/bin"
BIN_TARGET="`pwd`/doctrine"
cd "$SRC_DIR"
"$BIN_TARGET" "$#"
But db testdatanot created.
Same with creating php class from table:
php vendor/bin/doctrine doctrine:mapping:import YourAppBundle yml --filter="bugs"
But yml file not created.
Whats can be wrong?
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.
https://groups.google.com/forum/#!msg/doctrine-user/_ph183Kh-5o/_P_coljB-dcJ

Doctrine Cli on Windows

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

Categories