Answer the question
In order to leave comments, you need to log in
How to run an external program from a package in composer that is located in the directory of the package itself?
I'm trying to make my own composer package, based on a plugin in github. Here it is https://github.com/chapagain/php-swiss-ephemeris
There is one caveat here:
the php script uses and runs the external Swiss Ephemeris program in this plugin that I rely on it is located in the sweph folder.
I want to make my own composer package that would run an external program inside, receive data from it, then standard data processing would go on and bring it into the form that I need.
I currently have the following file structure:
src
--sweph
--Natal.php
vendor
composer.json
index.php Composer.json
content:
{
"name": "tripcollor/astro",
"description": "PHP library for calculations astro",
"keywords": [
"astrology"
],
"authors": [
{
"name": "tripcollor",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.6"
},
"require-dev": {
},
"autoload": {
"psr-4": {
"Astrology\\": "src"
}
}
}
<?php
namespace Astrology;
use DateTime;
class Natal
{
public function test()
{
$libPath = './sweph/';
putenv("PATH=$libPath");
$birthDate = new DateTime("1990-06-03T13:30:00Z");
$latitude = 55.5557;
$longitude = 52.5752;
$timezone = 0;
$timezone * (60 * 60);
$birthTimestamp = strtotime($birthDate->format('Y-m-d H:i:s'));
$utcTimestamp = $birthTimestamp - $offset;
$date = date('d.m.Y', $utcTimestamp);
$time = date('H:i:s', $utcTimestamp);
exec ("swetest -edir$libPath -b$date -ut$time -p0123456789ABCDEFGHIJKLMNOPQRSTUVWX -xz -emos -fPls -g, -head", $output_t);
print_r($output_t);
}
}
<?php
require './vendor/autoload.php';
use Astrology\Natal;
$Natal= new Natal();
$Natal->test();
Answer the question
In order to leave comments, you need to log in
The structure is not quite correct.
- index.php - strange file for package composer. What function does it perform?
- Your program should not be in the source folder - you need to either move it to bin, or pull it up with a separate package, or just pass the absolute path to the binary in new Ayurveda($binPath)
- Well, ./swe .. is a bit strange, you need use something like realpath(dirname(__FILE__))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question