Esempio n. 1
0
 public function getUser()
 {
     if (null === $this->user && Pimple::hasResource('user')) {
         $this->user = Pimple::getResource('user');
     }
     return $this->user;
 }
Esempio n. 2
0
 /**
  * Filter the supplied URL.
  *
  * @param string $url
  * @return mixed
  */
 public function direct($url)
 {
     if (!Pimple::hasResource('url-filter')) {
         return $url;
     } else {
         /* @var $filter callable */
         $filter = Pimple::getResource('url-filter');
         return $filter($url);
     }
 }
 public static function get()
 {
     if (!self::$key) {
         $paths = Pimple::hasResource('paths') ? Pimple::getResource('paths') : new Paths();
         $keyFile = $paths->getData() . '/activity-log/secret-session-cookie-key.php';
         if (file_exists($keyFile) && is_readable($keyFile)) {
             self::$key = trim(file_get_contents($keyFile));
         }
     }
     return self::$key;
 }
 public function getMessage($name, array $templateValues)
 {
     if (!array_key_exists($name, $this->anonymousMessages)) {
         throw new TemplateNotFound("Message template not found with name '{$name}'.");
     }
     $user = $this->user;
     if (!$user && Pimple::hasResource('user')) {
         $user = Pimple::getResource('user');
     }
     $userHandler = null;
     try {
         $userHandler = $this->handlerResolver->resolve('user');
     } catch (HandlerNotFound $e) {
         // OK to proceed without the user handler.  Will just treat as anonymous.
     }
     if (!$user || !$userHandler) {
         $template = $this->anonymousMessages[$name];
     } else {
         $template = $this->userMessages[$name];
         // Automatically include %user% value when available.
         $templateValues['%user%'] = $userHandler->createEntity($user->getId());
     }
     return $this->renderTemplateTags($template, $templateValues);
 }
Esempio n. 5
0
 /**
  * Setup the default changesets.  If a changeset has already been configured with a given
  * name, the default will not be applied.  This is done primarily to allow the
  * overrideChangesetPath() method to swap out the default paths during testing.
  *
  * @return void
  */
 protected function initChangesets()
 {
     $mainChangesetName = Env::getInstance()->getProjectNoun();
     $defaultChangesets = ['dewdrop-core' => $this->paths->getDewdropLib() . '/db/' . $this->dbType, $mainChangesetName => $this->paths->getPluginRoot() . '/db', 'dewdrop-test' => $this->paths->getDewdropLib() . '/tests/db/' . $this->dbType];
     if (Pimple::hasResource('dbdeploy.changesets')) {
         $defaultChangesets = array_merge($defaultChangesets, Pimple::getResource('dbdeploy.changesets'));
     }
     foreach ($defaultChangesets as $name => $path) {
         if (!array_key_exists($name, $this->changesets)) {
             $this->changesets[$name] = $path;
         }
     }
 }
Esempio n. 6
0
 /**
  * Generate a URL for the provided page and params that will match the
  * Silex routes set up by this class.
  *
  * @param ComponentInterface $component
  * @param string $page
  * @param array $params
  * @return string
  */
 public function url(ComponentInterface $component, $page, array $params = array())
 {
     $url = '/admin/' . $component->getName() . '/' . $this->application['inflector']->hyphenize($page) . $this->assembleQueryString($params, '?');
     if (Pimple::hasResource('url-filter')) {
         /* @var $filter callable */
         $filter = Pimple::getResource('url-filter');
         $url = $filter($url);
     }
     return $url;
 }
Esempio n. 7
0
 /**
  * Optionally supply an array of fields that can be used as an initial
  * set for this collection.
  *
  * @param array $fields
  * @param UserInterface $user
  */
 public function __construct(array $fields = null, UserInterface $user = null)
 {
     if (is_array($fields)) {
         foreach ($fields as $field) {
             $this->add($field);
         }
     }
     if (null !== $user) {
         $this->user = $user;
     } elseif (Pimple::hasResource('user') && Pimple::getResource('user') instanceof UserInterface) {
         $this->user = Pimple::getResource('user');
     }
 }
Esempio n. 8
0
 public function renderLinkUrl($primaryKeyValue)
 {
     $linkTemplate = $this->defaultLinkTemplate;
     $user = $this->user;
     if (null === $user && Pimple::hasResource('user') && Pimple::getResource('user') instanceof UserInterface) {
         $user = Pimple::getResource('user');
     }
     foreach ($this->roleSpecificLinkTemplates as $role => $roleSpecificLinkTemplate) {
         if ($user && $user->hasRole($role)) {
             $linkTemplate = $roleSpecificLinkTemplate;
         }
     }
     if (!$linkTemplate) {
         return null;
     }
     /* @var $urlFilter callable */
     $urlFilter = Pimple::getResource('url-filter');
     $linkTemplate = $urlFilter($linkTemplate);
     return sprintf($linkTemplate, $primaryKeyValue);
 }
Esempio n. 9
0
 /**
  * If this table has date_updated or datetime_updated columns, supply a
  * value for them automatically during update(). It also will assign
  * the current user ID as the updater if possible.
  *
  * @param array $data
  * @return array
  */
 public function augmentUpdatedDataArrayWithWhenAndByWhom(array $data)
 {
     // When
     if ($this->getMetadata('columns', 'date_updated')) {
         $data['date_updated'] = date('Y-m-d G:i:s');
     } elseif ($this->getMetadata('columns', 'datetime_updated')) {
         $data['datetime_updated'] = date('Y-m-d G:i:s');
     } elseif ($this->getMetadata('columns', 'updated_at')) {
         $data['updated_at'] = date('Y-m-d H:i:s');
     }
     // By whom
     /* @var \Dewdrop\Pimple $pimple */
     $pimple = Pimple::getInstance();
     /* @var \Dewdrop\Paths $paths */
     $paths = $pimple['paths'];
     if ($this->getMetadata('columns', 'updated_by_user_id')) {
         if ($paths->isWp()) {
             $data['updated_by_user_id'] = get_current_user_id();
         } elseif (Pimple::hasResource('user') && ($user = Pimple::getResource('user')) && isset($user['user_id']) && 0 < $user['user_id']) {
             $data['updated_by_user_id'] = $user['user_id'];
         }
     }
     return $data;
 }
Esempio n. 10
0
 protected function filterUrl($url)
 {
     if (Pimple::hasResource('url-filter')) {
         /* @var $filter callable */
         $filter = Pimple::getResource('url-filter');
         $url = $filter($url);
     }
     return $url;
 }
Esempio n. 11
0
 /**
  * Check to see if the supplied resource is present in the component's Pimple
  * or in the Dewdrop Pimple.
  *
  * @param string $name
  * @return bool
  */
 public function hasPimpleResource($name)
 {
     return isset($this->pimple[$name]) || DewdropPimple::hasResource($name);
 }
Esempio n. 12
0
 /**
  * Get the Permissions object for this component.
  *
  * @return Permissions
  */
 public function getPermissions()
 {
     if (!$this->permissions) {
         if (DewdropPimple::hasResource('admin.permissions-factory')) {
             /* @var $factory callable */
             $factory = DewdropPimple::getResource('admin.permissions-factory');
             $this->permissions = $factory($this);
         } else {
             $this->permissions = new Permissions($this);
         }
     }
     return $this->permissions;
 }
Esempio n. 13
0
 /**
  * Get the logged-in user row object for use when loading and saving per-user
  * filter settings.  Will attempt to retrieve this from Pimple if not set
  * explicitly.
  *
  * @return Row
  */
 public function getUser()
 {
     if (!$this->user && Pimple::hasResource('user')) {
         $user = Pimple::getResource('user');
         if ($user instanceof Row) {
             $this->user = $user;
         }
     }
     return $this->user;
 }