The actual question: is it possible to choose the PHP version (5.6, 7.1, 7.2, ...) to generate code?
I got a swagger.json from https://api.otto.market/docs
which should be an openapi.json or so, since the file contains "openapi": "3.0.3",. Anyway ...
What i found out so far is that they (swagger and openapi-generator) seem to have templates for the code generation.
And those templates are written in the language for the version in use.
F.e. this (openapitools/openapi-generator-cli)
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i /local/path/to/swagger.json \
-g php \
-o /local/path/to/generated/code/
creates a composer.json with
...
"require": {
"php": "^7.3 || ^8.0",
...
},
...
I now COULD use the templates and change the requirements.
But i think this would not be the target of a code generator.
Info about templates added to bottom.
What i guess is that there should be templates written for other PHP version.
But how would i choose them?
Are there any?
Swagger: as i read swagger came first, and openapi-generator is a fork.
So i tried swagger:
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate \
-i /local/path/to/swagger.json \
-l php \
-o /local/path/to/generated/code/
Swagger created code for PHP 5.5 (as of the generated composer.json).
But it brings warnings and the generated code looks "broken".
I actually do not wonder since the file is made for openapi": "3.0.3.
But what i see is: swagger has templates for PHP 5.5.
My personal current conclusion:
I can generate code real quick f.e. for an API that i do not really (have to) know.
But how does it help me if i cannot change the language version?
F.e. i need an API client in 2 projects.
One is in PHP 7.1 and the other one in 7.3. How do i solve this?
Anybody had to deal with this? Or any ideas?
INFO
templates: how to use templates:
Call docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli author template -g php -o /local/templates/
to save all templates to path templates/.
You then can f.e. copy the composer.mustache to f.e. deploy/templates/ and change it.
On generating code you use -t /local/deploy/templates to use your changed template.
Example:
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i /local/path/to/swagger.json \
-g php \
-o /local/path/to/generated/code/ \
-t /local/deploy/templates
Old versions of OpenAPI Generator (e.g. 3.0.0, 4.0.0) support old PHP versions.
To easily switch between OpenAPI Generator CLI versions, you may want to use the NPM CLI wrapper for OpenAPI Generator.
Related
I try to make a custom php extension for code Encryption purposes,
I followed this tutorial to make an custom extension: How to make a PHP extension
i get this warning when compiling the extension:
WARNING
The following arguments is invalid, and therefore ignored:
--enable-php-helloworld
i did all according to the tutorial, i build on windows.
what are possible things i do wrong.
I followed that section: https://stackoverflow.com/a/32575493/3103078
I replicated the code 1:1 (Os: Windows)
used commands:
phpize
configure --enable-php-helloworld
nmake
php -d extension=php_helloworld.so --re php_helloworld
Expected result:
>>>helloworld support
Actual Result:
>>>
reproduction:
mkdir php
start https://altushost-swe.dl.sourceforge.net/project/winflexbison/win_flex_bison3-latest.zip
set path=%path%;C:\your_path\to\bison
start https://altushost-swe.dl.sourceforge.net/project/gnuwin32/sed/4.2.1/sed-4.2.1-bin.zip
set path=%path%;C:\your_path\to\sed
start https://codeload.github.com/skvadrik/re2c/zip/refs/tags/2.1.1
set path=%path%;C:\your_path\to\re2c
start https://download.microsoft.com/download/5/C/3/5C3770A3-12B4-4DB4-BAE7-99C624EB32AD/windowssdk/winsdksetup.exe
rem after install
set path=%path%;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64
start https://windows.php.net/downloads/releases/php-devel-pack-7.3.29-Win32-VC15-x64.zip
rem install upper in php dir
phpize
configure --enable-php-helloworld
nmake
php -d extension=php_helloworld.so --re php_helloworld
The issue was not utilizing the php-src inside the sdk.
Also, on windows you need to use php-sdk-binary-tools, else it wont work when you compile it.
I'll do a tutorial on this soon.
I built a number of custom PHP extensions under windows 8-10 years ago. I made the move to Ubuntu Linux for all of my web stuff some years ago and find I need to create another custom extension. I'll be doing the development under Ubuntu this time.
I've created a very simple extension (a no-op actually) just to make sure I have the build process working. It's not.
Here is what I have done:
Cloned PHP from Git
Checked out PHP-5.5
Configured with --disable-all --enable-debug --enable-maintainer-zts \
--prefix=
Build PHP
Success php -i shows:
Zend Extension Build => API220121212,TS,debug
PHP Extension Build => API20121212,TS,debug
Created ext/a1 for my new, very simple extension
Created the basic extension (from Sara Goleman's book)
Ran phpize in ext/a1
Ran ./configure --enable-a1
Ran make
Build was successful.
Copied a1.so to the extensions directory
phpdir/bin/php -dextension=a1.so -v
Fails. Results in:
Module compiled with build ID=API20121212,NTS
PHP compiled with build ID=API20121212,TS,debug
So. Color me confused. According to what I've read, the phpize command is supposed to match the extension build settings to the php build settings.
I've apparently missed something basic here somewhere.
Help will be most appreciated.
Its hard to say what exactly was going wrong, I can only say that the extension was build using a different config than the php version.
I will describe some reproducible steps how to compile a most basic extension with debug symbols within the PHP source folder. The extension contains no code except of some boilerplate code created by ext_skel. It just describes the compilation process on UNIX. It is a shell script, you might execute it.
#!/bin/sh
# Should work for all PHP5 versions
VERSION="5.6.9"
# Download the PHP source code
wget \
--continue "http://de2.php.net/get/php-$VERSION.tar.gz/from/this/mirror" \
-O "php-$VERSION".tar.gz
tar xf "php-$VERSION.tar.gz" && cd "php-$VERSION/ext"
# Create a hello extension from skeletons
./ext_skel --extname="hello"
# Uncomment two lines in ext/hello/config.m4
# Read the comments there and you'll know what I'm doing
sed -ri.original \
-e 's/(dnl )(PHP_ARG_ENABLE\(hello)/\2/' \
-e 's/(dnl )(\[ --enable-hello)/\2/' \
hello/config.m4
# Build PHP and the extension
cd ..
./buildconf --force
./configure \
--enable-debug --enable-maintainer-zts \
--enable-hello=shared
make -j
# Test if it is working
sapi/cli/php \
-dextension=modules/hello.so \
-r 'var_dump(extension_loaded("hello"));'
You can now start to enter code to ext/hello/hello.c and create your extension. If you want to compile the changes you make just issue make without arguments.
Since we've compiled using --debug we you can now use gdb to debug the C code and explore how PHP internally works. To start a debugging session use:
gdb sapi/cli/php
...
(gdb) break main
(gdb) run -dextension=modules/hello.so some.php
Of course you'll mostly set breakpoints into your extension functions rather than in the php main() function once you've added code to the extension. However, this should show the basic steps to get there.
Have fun! :)
gdb
For offline development I would like to make make a standalone PHP 5.4 binary so I can use the PHP self hosting option.
eg php -S localhost:8000
Which would startup a server for hosting PHP files.
Since installing and configuring PHP 5.4 on mac is not trival for non tech people. I would like to be able to include a working PHP binary in my files. So essentially I can run.
./php -S localhost:8000 in my folder and it will work.
I have followed the instruction here to create a standalone PHP binary by running on the source code.
./configure --enable-static --enable-cgi --enable-mbstring\
--enable-force-cgi-redirect \
--with-config-file-path=/etc/php5cgi \
--prefix=/usr/local/php5cgi \
--with-curl \
--enable-sockets \
--with-zlib --with-zlib-dir=/usr/include \
--with-pear
Then editing the Makefile to have -all-static
BUILD_CGI = <other commands here> $(ZEND_EXTRA_LIBS) -all-static -o $(SAPI_CGI_PATH).
BUILD_CLI = <other commands here> $(ZEND_EXTRA_LIBS) -all-static -o $(SAPI_CGI_PATH).
This does work. File is standalone.
But when I run the binary.
./php-cgi -h
There is no "-S" option for the built in webserver?
Do I need to change something in my configure options to allow the builtin webserver? My source was downloaded from PHP.net (I did download the 5.5 latest source, but that still does have the -S option).
Thanks, John.
thanks to #devZer0
I cd'ed into
sapi/cgi/php-cgi
and tried to run this.
Needed to cd into sapi/cli/php
That works now! php -h return the -S option for webserver.
So, I have a php script that integrates with BitBucket's API and make changes to some local/shared repositories.
To do that, I use --git-dir and --work-tree [when applicable] together with every command, as in:
/usr/bin/git --git-dir=/var/www/staging.repo/.git --work-tree=/var/www/staging.repo merge "origin/master" 2>&1; echo $?
I use git version 1.7.0.4 on my development environment, and git version 1.5.6.5 on the live server. The reason for it is that there's no newer version of git for Debian Lenny (5), so I'm stuck with the older one.
The problem is, some of the commands that correctly accept --work-tree and --git-dir on git v1.7 doesn't seem to care much about it on the older version. One example is:
/usr/bin/git --git-dir=/var/www/staging.repo/.git --work-tree=/var/www/staging.repo merge "origin/master" 2>&1; echo $?
That outputs:
fatal: /usr/bin/git-merge cannot be used without a working tree.
So, how can I make broad use of those parameters using git 1.5.6.5?
Solution:
Downloaded git source:
myself:/some/folder$ curl -O http://git-core.googlecode.com/files/git-1.7.7.tar.gz
Installed:
myself:/some/folder/git-1.7.7.tar.gz$ ./configure
myself:/some/folder/git-1.7.7.tar.gz$ make
myself:/some/folder/git-1.7.7.tar.gz$ sudo make install
Done! :)
Ref: http://www.mikepilat.com/blog/2011/06/how-to-build-git-from-source-on-ubuntu/
Please compile the latest git.
Yes, some commands don't observe those parameters. You can try and set their equivalent environment variables instead.
I have installed PHP Documentor through PEAR. but output option is not working.
when i use simple command like
phpdoc -d source/path -t target/path --template responsive
it works fine. but when i use -o or --output option like this
phpdoc -d source/path -t target/path -o PDF:default:*
it gives following error.
[RuntimeException]
The "-o" option does not exist.
i have tried other output formats as well like -o HTML:Smarty:PHP and -o HTML:Smarty:default but the result is same.
the -o option does not exist on phpdocs 2
Look option whit:
phpdoc -h
In the new version 2. * yet there is no such pdf template. There is not also the option -o.
there are only http://www.phpdoc.org/templates
template selection
phpdoc --template="clean" --template="checkstyle" -d .
BTW I use the older version (1.4.4) I wanted to save to pdf.
phpdoc -o PDF:default:default -t ./docs -d ./
But created an bad document. Maybe version 1.4.4 does not work with PHP 5.5.11 on the issue in PDF format.
I managed in version 1.4.4 only generate HTML.
phpdoc -o HTML:frames:earthli -t ./docs -d ./
So I went back to version 2 * and I wait pdf template.