+ /**
+ * Get path from bundled file
+ *
+ * @param string file The bundled file path
+ * @param int lineno The template line where the error occurred
+ * @param Source source The source context where the error occurred
+ * @param \Exception prev The previous exception
+ *
+ * @return string The resolved file path
+ */
+ public function getLocated($file, int $lineno = 0, Source $source = null, \Exception $prev = null) {
+ /*TODO: add a @jquery magic feature ?
+ if ($file == '@jquery') {
+ #header('Content-Type: text/plain');
+ #var_dump($inputs);
+ #exit;
+ return $this->config['jquery'];
+ }*/
+
+ //Check that we have a / separator between bundle name and path
+ if (($pos = strpos($file, '/')) === false) {
+ throw new Error(sprintf('Invalid path "%s"', $file), $token->getLine(), $stream->getSourceContext());
+ }
+
+ //Set bundle
+ $bundle = substr($file, 0, $pos);
+
+ //Set path
+ $path = substr($file, $pos + 1);
+
+ //Check for bundle suffix presence
+ //XXX: use "bundle templates automatic namespace" mimicked behaviour to find intended bundle and/or path
+ //XXX: see https://symfony.com/doc/4.3/templates.html#bundle-templates
+ if (strlen($bundle) < strlen('Bundle') || substr($bundle, -strlen('Bundle')) !== 'Bundle') {
+ //Append Bundle in an attempt to fix it's naming for locator
+ $bundle .= 'Bundle';
+
+ //Check for public resource prefix presence
+ if (strlen($path) < strlen('Resources/public') || substr($path, 0, strlen('Resources/public')) != 'Resources/public') {
+ //Prepend standard public path
+ $path = 'Resources/public/'.$path;
+ }
+ }
+
+ //Resolve bundle prefix
+ try {
+ $prefix = $this->locator->locate($bundle);
+ //Catch bundle does not exist or is not enabled exception
+ } catch(\InvalidArgumentException $e) {
+ //Fix lowercase first bundle character
+ if ($bundle[1] > 'Z' || $bundle[1] < 'A') {
+ $bundle[1] = strtoupper($bundle[1]);
+ }
+
+ //Detect double bundle suffix
+ if (strlen($bundle) > strlen('_bundleBundle') && substr($bundle, -strlen('_bundleBundle')) == '_bundleBundle') {
+ //Strip extra bundle
+ $bundle = substr($bundle, 0, -strlen('Bundle'));
+ }
+
+ //Convert snake case in camel case
+ if (strpos($bundle, '_') !== false) {
+ //Fix every first character following a _
+ while(($cur = strpos($bundle, '_')) !== false) {
+ $bundle = substr($bundle, 0, $cur).ucfirst(substr($bundle, $cur + 1));
+ }
+ }
+
+ //Resolve fixed bundle prefix
+ try {
+ $prefix = $this->locator->locate($bundle);
+ //Catch bundle does not exist or is not enabled exception again
+ } catch(\InvalidArgumentException $e) {
+ //Bail out as bundle or path is invalid and we have no way to know what was meant
+ throw new Error(sprintf('Invalid bundle name "%s" in path "%s". Maybe you meant "%s"', substr($file, 1, $pos - 1), $file, $bundle.'/'.$path), $token->getLine(), $stream->getSourceContext(), $e);
+ }
+ }
+
+ //Return solved bundle prefix and path
+ return $prefix.$path;