Conversation
|
The thing I absolutely don't like is the unmotivated array mixture of the permissions. That is yelling "YAGNI" in my ears, i.e. it looks like it is waiting for future extensions that probably will never happen. You have designed the I am also unsure why you are not adding these new parameters into I cannot really argue about the need for this enhancement. File permissions as well as file/group ownership is a tricky thing, and any fixed choice is likely wrong in at least some situations. I would assume any user creating a compiled container already has some deployment process in place where the compilation step is happening before the code is pushed live, and probably some intermediate step is correcting the file permissions and ownership to the requested level of security anyways - contradicting myself as this assumption is also wrong in at least some situations. I'll leave that up for someone else to consider. |
Originally I had included changes that also allowed a user to define group permissions, which meant I was passing more than one permission along. I didn't end up including those changes as part of this PR. That said, I've updated the PR to remove the use of an array.
As you noted, to avoid breaking existing implementations, the optional arguments would need to be tacked to the end of the function signature. However, this would require users to define what I suspect are rarely-changed values, in order to reach those arguments. I felt a standalone method for setting these permissions more closely aligned with the current design pattern of the container builder, and would be least impactful now, and in the future. |
An additional parameter could be added without specifying unneeded values using named arguments: $builder->enableCompilation($directory, filePermissions: 0644, directoryPermissions: 0755);A way to use just one parameter would be to allow the user to specify a mask. The default would be You would apply the mask on the existing hardcoded values using chmod($tmpFile, 0666 & $umask); |
|
Could we just change the default permissions to 0775 and 0664? That would be a much simpler PR, anything we can do to add more options is welcome. |
When you enable compilation in PHP-DI:
Directories are created with permission
0777and files are created with0666. This grants read+write to theothergroup in a linux environment, which is widely accepted as unsafe practice.It is safer to create directories using
0775and files with0664by default.To that extent, I believe the compiler should be further enhanced, to allow users to configure permissions for better control over their environments.
This change sets new default permissions, and introduces a new
cachePermissions()method, which a user can use to override those default permissions: