Execute the generated sql , in the local Windows 10 , in the liunx container, no records are queried (related to directory_separator)
1. Execute the generated sql, which can be found in the local Windows 10. In the liunx container, no records are found. Print records under Windows 10. as shown in Figure 1
$rawSchema = ThemeAssetEntity::select('schema')
->where('theme_id', '=', $this->getThemeId())
->where('category', '=', ThemeAssetEntity::CATEGORY_PAGE)
->where('asset_key', 'regexp', $this->themeLayout->getTemplateExtensionsPattern($basename))
->first();
var_dump($rawSchema);
exit;
2. Print the record under the liunx container. The result is null. as shown in Figure 2
3. Decide to print the generated sql, you need to delete ->first() . Do a comparison. The difference between Windows 10 and Linux is as follows, and then execute SQL under Linux in MySQL, and the query result is NULL. The difference is pages/\ and pages//. as shown in Figure 3
$rawSchema = ThemeAssetEntity::select('schema')
->where('theme_id', '=', $this->getThemeId())
->where('category', '=', ThemeAssetEntity::CATEGORY_PAGE)
->where('asset_key', 'regexp', $this->themeLayout->getTemplateExtensionsPattern($basename));
$query = str_replace(array('?'), array('\'%s\''), $rawSchema->toSql());
$query = vsprintf($query, $rawSchema->getBindings());
dump($query);
exit;
select `schema` from `theme_asset` where `theme_id` = '96b1c8b9-5b18-4760-9e26-50ab009ac011' and `category` = 'page' and `asset_key` regexp '^pages/\product_detail(\.blade\.php|\.liquid|\.json)'
select `schema` from `theme_asset` where `theme_id` = '96dcab33-3e1d-4279-ab96-39693f03515f' and `category` = 'page' and `asset_key` regexp '^pages//product_detail(\.blade\.php|\.liquid|\.json)'
4. Analyze the functions that generate regular expressions. Print the directory_separator, the results of the two environments are inconsistent. are \ and /
public function getTemplateExtensionsPattern($basename)
{
$escapeDot = array_map(function($extension){
return str_replace('.', '\\.' ,$extension);
}, $this->getTemplateExtensions());
print_r(DIRECTORY_SEPARATOR);
exit;
return sprintf('^%s%s%s%s', $this->getPageDir(), '/'.DIRECTORY_SEPARATOR, $basename, '('.join('|', $escapeDot) .')');
}
\
/
5. Delete the .directory_separator, because it is inconsistent in the two operating systems. And because only / is used in the table, there is no need to escape. The resulting SQL is consistent in both operating systems. and can query the results. as shown in Figure 4
public function getTemplateExtensionsPattern($basename)
{
$escapeDot = array_map(function($extension){
return str_replace('.', '\\.' ,$extension);
}, $this->getTemplateExtensions());
return sprintf('^%s%s%s%s', $this->getPageDir(), '/', $basename, '('.join('|', $escapeDot) .')');
}
"select `schema` from `theme_asset` where `theme_id` = '96dcab33-3e1d-4279-ab96-39693f03515f' and `category` = 'page' and `asset_key` regexp '^pages/product_detail(\.blade\.php|\.liquid|\.json)'"



