如何导入PHP exec / system / etc中使用的自定义bash函数?

I'm writing a command-line application that will substitute a bunch of bash functions and manual work made by a team of developers. Currently, half of what we usually do is inside a ~/.functions file that is sourced in the ~/.bash_profile of each developer.

My command-line application is written in PHP, and for a while I would need to run some of those functions from inside my application. However, the following code would not work, the output says it cannot find the given function:

exec('bash my_legacy_functions.sh');
exec('my_custom_legacy_function param1 param2');

I may be wrong, but I could understand that every exec() call runs a command in a separate process, meaning the functions would not be available for subsequents exec() calls. Is this right, and if yes, would it be possible to override this behaviour without having to bundle everything into one call?

In the end it turns out the default shell was not bash, and on top of that source is not a common command in bash. I found by this other question's answer that the solution is something like:

function run($cmd) {
    exec("bash -c 'source my_legacy_functions.sh; $cmd'");
}