demo-functions.php 633 B

123456789101112131415161718192021222324
  1. <?php
  2. /** @noinspection PhpUndefinedFieldInspection */
  3. trait DemoFunctions
  4. {
  5. public function demoData($file = null)
  6. {
  7. if (!$file) {
  8. $this->setResponse(422, 'Demo file was not supplied');
  9. return false;
  10. }
  11. $path = dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'demo_data' . DIRECTORY_SEPARATOR . $file;
  12. if (file_exists($path)) {
  13. $data = file_get_contents($path);
  14. $data = json_decode($data, true);
  15. $this->setResponse(200, 'Demo data for file: ' . $file, $data['response']['data']);
  16. return $data;
  17. } else {
  18. $this->setResponse(404, 'Demo data was not found for file: ' . $file);
  19. return false;
  20. }
  21. }
  22. }