Let served make a proper name if none is set (instead of defaulting to 'served')
iammikek opened this issue · comments
@sinnbeck I'm looking at ways we could introduce this feature and wonder how you'd like to approach it?
Are you imagining something like how heroku does eg "airy-craig" or "soaring-peaks"?
We would need to preserve the name once it was created. Would it be viable for us to write this name into the .env as SERVER_NAME?
I came across https://mattstauffer.com/blog/generating-synonymous-heroku-style-server-names-with-lumen/ which might give us a head start.
What do you think?
Really interesting. We just need to make sure that it does not change between builds. I worry people will complain if we add it to their env without asking. I was considering running slug on the folder name
Using a folder name sounds sensible.
So we'd default to that, as a slug, and then allow it to be overridden in the .env if required.
We'd need to get access to it via a method that replaces the calls to
$servedName = config('served.name');
so I guess we could introduce a method in a new trait for this?
Yeah sounds like a good plan. Use config if not null and fallback to slugged folder name
@iammikek I am considering using Str::slug($name, '_')
to ensure that the name is always valid. Any thoughts?
I have done a quick test with and this seems to do the job
public function getProjectFolderName(): string
{
return Str::afterLast(base_path(), '/');
}
and something like this go get the proper name
public function projectName(): string
{
if ($configName = config('served.name')) {
if (!$this->testAllowedCharacters($configName)) {
throw new \Exception(); //replace with proper exception
}
return $configName;
}
return Str::slug($this->getProjectFolderName(), '_');
}
Sure. I will try to get something up and running soon :)