Exemplo n.º 1
0
 /**
  * Test camelize
  */
 public function testCamelize()
 {
     $this->assertEquals('camelIzedWords', String::camelize('camel-ized-words'));
     $this->assertEquals('CamelIzedWords', String::camelize('Camel-Ized-Words'));
     $this->assertEquals('camelIzedWords', String::camelize('Camel.Ized.Words', '.', true));
     $this->assertEquals('CamelIzedWords', String::camelize('camel.ized.words', '.', false));
 }
Exemplo n.º 2
0
 /**
  * Extract values from a structure
  *
  * @param  object $object
  * @return array
  */
 public function extract($object)
 {
     $data = $this->getMapper()->extract($object);
     if (isset($data['properties']) && is_array($data['properties'])) {
         foreach ($data['properties'] as $key => $value) {
             $newKey = String::camelize($key);
             if (is_array($value) && array_key_exists('value', $value)) {
                 $data['properties'][$key] = $value['value'];
             }
             if ($newKey != $key) {
                 $data['properties'][$newKey] = $data['properties'][$key];
                 unset($data['properties'][$key]);
             }
         }
     }
     return $data;
 }
Exemplo n.º 3
0
 /**
  * Settings admin
  */
 public function indexAction()
 {
     $params = $this->params();
     $request = $this->getRequest();
     $section = $params->fromRoute('section', null);
     $permissions = $this->getPermissionsModel();
     if (empty($section)) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $model = $this->getServiceLocator()->get('Grid\\Core\\Model\\Settings\\Model');
     $settings = $model->find($section);
     if (empty($settings)) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     if (!$permissions->isAllowed('settings.' . $section, 'edit')) {
         $this->getResponse()->setStatusCode(403);
         return;
     }
     /* @var $form \Zend\Form\Form */
     $name = ucfirst(String::camelize($section));
     $form = $this->getServiceLocator()->get('Form')->get('Grid\\Core\\Settings\\' . $name);
     if (empty($form)) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $form->setHydrator($model->getMapper())->bind($settings);
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid() && $settings->save()) {
             $this->messenger()->add('settings.form.all.success', 'settings', Message::LEVEL_INFO);
             return $this->redirect()->toUrl('?refresh');
         } else {
             $this->messenger()->add('settings.form.all.failed', 'settings', Message::LEVEL_ERROR);
         }
     }
     return array('section' => $section, 'name' => $name, 'form' => $form, 'textDomain' => $model->getMapper()->getDefinitions()->getTextDomain($section));
 }
Exemplo n.º 4
0
 /**
  * Get property names
  *
  * @return array
  */
 public function getPropertyNames()
 {
     $result = array();
     foreach ($this->getRawPropertyNames() as $rawName) {
         $result[] = String::camelize($rawName);
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * Guess plugin classes for a name
  *
  * @param   string  $name
  * @return  array
  */
 protected function guessPluginClassesForName($name)
 {
     $camelized = String::camelize($name, '_', false);
     return array('Zork\\View\\Helper\\' . $camelized, 'Zend\\View\\Helper\\' . $camelized, 'Zork\\I18n\\View\\Helper\\' . $camelized, 'Zend\\I18n\\View\\Helper\\' . $camelized, 'Zork\\Form\\View\\Helper\\' . $camelized, 'Zend\\Form\\View\\Helper\\' . $camelized);
 }
Exemplo n.º 6
0
 /**
  * Install a package
  */
 public function installAction()
 {
     $extra = array();
     $params = $this->params();
     $vendor = $params->fromRoute('vendor');
     $subname = $params->fromRoute('subname');
     $name = $vendor . '/' . $subname;
     $service = $this->getServiceLocator();
     $model = $service->get('Grid\\Core\\Model\\Package\\Model');
     $forms = $service->get('Form');
     $package = $model->find($name);
     if (!$model->getEnabledPackageCount()) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     if (empty($package)) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     if (!$package->canInstall()) {
         $this->getResponse()->setStatusCode(403);
         return;
     }
     $formName = 'Grid\\Core\\Package\\Install\\' . String::camelize($vendor, null, false) . '\\' . String::camelize($subname, null, false);
     /* @var $forms \Zork\Form\FormService */
     if ($forms->has($formName)) {
         /* @var $form \Zork\Form\Form */
         $extraValid = false;
         $request = $this->getRequest();
         $form = $forms->get($formName);
         if ($request->isPost()) {
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $extra = $form->getData();
                 $extraValid = true;
             }
         }
         if (!$extraValid) {
             $form->add(array('type' => 'Zork\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => array('value' => 'admin.packages.action.install')));
             return array('name' => $name, 'package' => $package, 'form' => $form);
         }
         if ($form instanceof TransformValues) {
             $extra = $form->transformValues($extra);
         }
     }
     if (!$model->install($package, $extra)) {
         $this->messenger()->add('admin.packages.install.failed', 'admin', Message::LEVEL_ERROR);
         return $this->redirect()->toRoute('Grid\\Core\\Admin\\Package\\View', array('locale' => (string) $this->locale(), 'vendor' => $vendor, 'subname' => $subname));
     }
     return $this->redirect()->toRoute('Grid\\Core\\Admin\\Package\\Update', array('locale' => (string) $this->locale()));
 }