modworkspace.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Workspaces are isolated packaging environments. They are currently not used in MODX.
  12. *
  13. * @property string $name The name of the Workspace
  14. * @property string $path The absolute path of the Workspace
  15. * @property timestamp $created The time this Workspace was created on
  16. * @property boolean $active Whether or not this Workspace is active
  17. * @property array $attributes An array of attributes for this Workspace
  18. *
  19. * @package modx
  20. */
  21. class modWorkspace extends xPDOSimpleObject {
  22. /**
  23. * Overrides xPDOObject::save to set the createdon date.
  24. *
  25. * {@inheritdoc}
  26. */
  27. public function save($cacheFlag= null) {
  28. if ($this->_new && !$this->get('created')) {
  29. $this->set('created', strftime('%Y-%m-%d %H:%M:%S'));
  30. }
  31. $saved= parent :: save($cacheFlag);
  32. return $saved;
  33. }
  34. /**
  35. * Overrides xPDOObject::get() to replace path settings.
  36. *
  37. * {@inheritdoc}
  38. */
  39. public function get($k, $format = null, $formatTemplate= null) {
  40. $result= parent :: get($k, $format, $formatTemplate);
  41. if ($k === 'path' && strpos($result, '{') !== false) {
  42. $replacements = array();
  43. foreach ($this->xpdo->config as $key => $value) {
  44. $_pos = strrpos($key, '_');
  45. if ($_pos > 0 && (substr($key, $_pos + 1) === 'path')) {
  46. $replacements['{' . $key . '}'] = $value;
  47. }
  48. }
  49. $result = str_replace(array_keys($replacements), array_values($replacements), $result);
  50. }
  51. return $result;
  52. }
  53. }