Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using .env files with phar file #442

Closed
arnolem opened this issue Apr 26, 2024 · 4 comments · Fixed by #450
Closed

Using .env files with phar file #442

arnolem opened this issue Apr 26, 2024 · 4 comments · Fixed by #450

Comments

@arnolem
Copy link

arnolem commented Apr 26, 2024

Hello,

I don't understand how to use .env with .phar applications

1- Create a task into /projets/castor-test/castor.php

<?php

use Castor\Attribute\AsTask;

use function Castor\load_dot_env;

#[AsTask]
function test(): void
{
    dump(load_dot_env());
}

2- Create a .env file /projets/castor-test/.env

TEST=TOTO

3- Repack with castor

vendor/bin/castor repack

the .env is not embedded in the phar. probably normal?
image

4- Use the test Task

./my-app.linux.phar test

An error occurred

Unable to read the "/projets/.env" environment file. 

But why the .env file is load from /projets on not from the current directory /projets/castor-test/ ?

Thanks. ♥️

@lyrixx
Copy link
Member

lyrixx commented May 3, 2024

I guess the .env file is searched inside the phar and not on your disk.
AND it's not inside the phar (Not packing it may be an error)

I imagine there are other similar issues with repacked application.

But this is not really easy. It's hard to tell if the repacked app should search on disk, on in the phar... I have no answer for now...

Maybe someone have a nice point of vieux to share!

@joelwurtz
Copy link
Member

I think the default behavior for those use case should be :

  1. First search on disk
  2. Then search on phar if not found on disk

@lyrixx
Copy link
Member

lyrixx commented May 3, 2024

@joelwurtz That means we have to embed everything 😬. I don't like that.

But I just test, and indeed there is an issue with .env. I'm on it

@arnolem
Copy link
Author

arnolem commented May 4, 2024

Thanks @lyrixx 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants