Skip to content

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

Description

@theasteve

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  %} 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions