timber / starter-theme

The "_s" for Timber: a dead-simple theme that you can build anything from
MIT License
818 stars 278 forks source link

Create a namespaced version of Timber with Mozart #138

Closed jstask82 closed 10 months ago

jstask82 commented 1 year ago

I tried to install the Plugin Slim SEO Schema that uses this namespaced version of twig which causes a conflict with Timbers Twig. Maybe the solution is to generate a namespaced version of Timber with Mozart. I think i managed to do so, but have problems with calling the class. My composer.json looks like this:

{
  "name": "aaronkessler/wordpress-theme",
  "description": "My portfolio website theme",
  "type": "wordpress-theme",
  "minimum-stability": "stable",
  "authors": [
    {
      "email": "jared@upstatement.com",
      "name": "jarednova"
    },
    {
      "email": "mail@aaronkessler.de",
      "name": "Aaron Kessler"
    }
  ],
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    }
  ],
  "require": {
    "timber/timber": "1.*",
    "vlucas/phpdotenv": "^5.4",
    "mindkomm/timmy": "^0.14.9"
  },
  "require-dev": {
    "phpunit/phpunit": "^9",
    "coenjacobs/mozart": "^0.7.1"
  },
  "config": {
    "allow-plugins": {
      "composer/installers": true
    }
  },
  "scripts": {
    "post-install-cmd": [
      "\"vendor/bin/mozart\" compose",
      "composer dump-autoload"
    ],
    "post-update-cmd": [
      "\"vendor/bin/mozart\" compose",
      "composer dump-autoload"
    ]
  },
  "extra": {
    "mozart": {
      "dep_namespace": "Aaronkessler\\",
      "dep_directory": "/build/",
      "classmap_directory": "/build/",
      "classmap_prefix": "Aaronkessler_",
      "packages": [
        "timber/timber"
      ],
      "excluded_packages": [
        "upstatement/routes"
      ],
      "override_autoload": {
        "twig/twig": {
          "psr-4": {
            "Twig\\": "src/"
          }
        },
        "twig/cache-extension": {
          "psr-4": {
            "Twig\\": "lib/Twig/"
          }
        }
      }
    }
  }
}

inside functions.php i am calling: $timber = new Aaronkessler\Timber\Timber(); but i get an Fatal error: Uncaught Error: Class "Aaronkessler\Timber\Timber" not found

szepeviktor commented 1 year ago

Hello @jstask82!! šŸ‘‹šŸ»

dep_directory defines the directory the files of the package will be stored in. Note that the directory needs to correspond to the namespace being used in your autoloader and the namespace defined for the bundled packages. Best results are achieved when your projects are using the PSR-4 autoloader specification.

says the documentation, so you need

  "autoload": {
    "psr-4": {
      "Aaronkessler\\": "build/"
    }
  },
jstask82 commented 1 year ago

Hey @szepeviktor

Thank you very much šŸ¬. This worked, but the error with Slim SEO Schema is almost the same. Now it's Fatal error: Uncaught TypeError: twig_get_attribute(): Argument #1 ($env) must be of type Aaronkessler\Twig\Environment, eLightUp\Twig\Environment given, called in [...]/plugins/slim-seo-schema/vendor/elightup/twig/Twig/Environment.php(358) : eval()'d code on line 37 and defined in [...]/themes/aaronkessler/build/Twig/Extension/CoreExtension.php:1400 but I think it's up on eLightUp to fix this.

szepeviktor commented 1 year ago

I can fix all errors. Please hire me. I pay you ā‚¬1/hour for that!