Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Class 'Spyc' not found in Config.php #73

Open
theasteve opened this issue Jun 18, 2018 · 0 comments
Open

Fatal error: Class 'Spyc' not found in Config.php #73

theasteve opened this issue Jun 18, 2018 · 0 comments

Comments

@theasteve
Copy link

I'm currently working with PHP version 7.1.7 on OS High Sierra. It seems Spyc is not able to read the variables in the config.yml file. Following the documentation I been trying to set the API Key for Google Analytics. This is what my composer.json file looks like:


{
  "name": "nyco/wp-config",
  "version": "0.0.5",
  "type": "wordpress-muplugin",
  "license": "GPL-3.0+",
  "description": "A WordPress package for environment configuration.",
  "homepage": "https://github.com/cityofnewyork/nyco-wp-config",
  "authors": [
    {
      "name": "Devon Hirth",
      "email": "dehirth@nycopportunity.nyc.gov",
      "homepage": "https://github.com/devowhippit"
    }
  ],
  "keywords": [
    "wordpress",
    "environment",
    "configuration"
  ],
  "support": {
    "issues": "https://github.com/cityofnewyork/nyco-wp-config/issues"
  },
  "require": {
    "composer/installers": "~1.0",
    "mustangostang/spyc": "^0.6.2",
    "illuminate/encryption": "^5.6"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "3.*",
    "codeception/codeception": "^2.3"
  },
  "scripts": {
    "lint": [
      "vendor/bin/phpcs --standard=standard.xml --extensions=php --ignore=vendor/ ."
    ],
    "fix": [
      "vendor/bin/phpcbf --standard=standard.xml --extensions=php --ignore=vendor/ ."
    ]
  }
}

I created the file mu-plugins/mu-autoloader.php as stated in the documentation of wp-config

The plugin comes in a directory, so you will need to create an mu-plugin autoloader to get it to be used by your WordPress installation

mu-plugins/mu-autoloader.php

namespace MustUsePlugins;

const PLUGINS = [
  '/wp-config/Config.php',
];

for ($i=0; $i < sizeof(PLUGINS); $i++) {
  if (file_exists(WPMU_PLUGIN_DIR . PLUGINS[$i]))
    require WPMU_PLUGIN_DIR . PLUGINS[$i];
}

When I browsed to localhost:8000 it shows the following error message:

Fatal error: Class 'Spyc' not found in /var/www/html/wp-content/mu-plugins/wp-config/Config.php on line 37

Which is produced in the following line:

if (file_exists($path . 'config.yml')) {
  $config = Spyc::YAMLLoad($path . 'config.yml');

When I remove mu-autoloader.php file I'm able to load the page on the browser but without the environment being read by the following template:

{% if function('getenv', 'GOOGLE_ANALYTICS') != '' %}
  <script async src='https://www.googletagmanager.com/gtag/js?id={{ function('getenv', 'GOOGLE_ANALYTICS') }}'></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', "{{ function('getenv', 'GOOGLE_ANALYTICS') }}");
  </script>
{% endif  %} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant