Inheritance: extends Model
コード例 #1
0
ファイル: Utils.php プロジェクト: jarves/jarves
 /**
  * Gets the item from the administration entry points defined in the config.json, by the given code.
  *
  * @param string  $code <bundleName>/news/foo/bar/edit
  *
  * @return EntryPoint
  */
 public function getEntryPoint($code)
 {
     if ('/' === $code) {
         return null;
     }
     $path = $code;
     if (substr($code, 0, 1) == '/') {
         $code = substr($code, 1);
     }
     if (false === strpos($code, '/')) {
         $path = '';
     }
     $bundleName = $code;
     if (false !== strpos($code, '/')) {
         $bundleName = substr($code, 0, strpos($code, '/'));
         $path = substr($code, strpos($code, '/') + 1);
     }
     //$bundleName = ucfirst($bundleName) . 'Bundle';
     $config = $this->jarves->getConfig($bundleName);
     if (!$path && $config) {
         //root
         $entryPoint = new EntryPoint();
         $entryPoint->setType(0);
         $entryPoint->setPath($code);
         $entryPoint->setChildren($config->getEntryPoints());
         $entryPoint->setBundle($config);
         return $entryPoint;
     }
     $entryPoint = null;
     if ($config) {
         while (!($entryPoint = $config->getEntryPoint($path))) {
             if (false === strpos($path, '/')) {
                 break;
             }
             $path = substr($path, 0, strrpos($path, '/'));
         }
     }
     return $entryPoint;
 }
コード例 #2
0
ファイル: JarvesBundle.php プロジェクト: jarves/jarves
 /**
  * Setup AutoCrud
  *
  * @param \Jarves\Configuration\Bundle[] $bundleConfigs
  */
 protected function setupObjects(array $bundleConfigs)
 {
     $objectsEntryPoint = $bundleConfigs['jarves']->getEntryPoint('object');
     foreach ($bundleConfigs as $bundleConfig) {
         /** @var EntryPoint[][] $objectEntryPoints */
         $objectEntryPoints = [];
         //read all entry points for each object
         if ($bundleConfig->getAllEntryPoints()) {
             foreach ($bundleConfig->getAllEntryPoints() as $entryPoint) {
                 if ($entryPoint->getObject()) {
                     $objectEntryPoints[$entryPoint->getObject()][$entryPoint->getType()] = $entryPoint;
                 }
             }
         }
         $entryPointsForThisBundle = [];
         if ($bundleConfig->getObjects()) {
             foreach ($bundleConfig->getObjects() as $object) {
                 if (!isset($objectEntryPoints[$object->getKey()])) {
                     //this object does not have any entry point to manage.
                     if (!$object->getAutoCrud()) {
                         //jarves should not autobuild entry points
                         continue;
                     }
                     $entryPoint = new EntryPoint();
                     $entryPoint->setPath(lcfirst($object->getId()));
                     $entryPoint->setType('combine');
                     $entryPoint->setObject($object->getKey());
                     $entryPoint->setLink(true);
                     $entryPoint->setIcon('#' . ($object->isNested() ? 'icon-list-nested' : 'icon-list'));
                     $entryPoint->setLabel($object->getLabel() ?: $object->getKey());
                     $entryPointsForThisBundle[] = $entryPoint;
                     $objectEntryPoints[$entryPoint->getObject()][$entryPoint->getType()] = $entryPoint;
                 }
             }
         }
         if ($entryPointsForThisBundle) {
             //we added some autoCrud entry points
             $bundleObjectContainerEntryPoint = new EntryPoint();
             $bundleObjectContainerEntryPoint->setPath($bundleConfig->getName());
             $bundleObjectContainerEntryPoint->setLink(true);
             $bundleObjectContainerEntryPoint->setLabel($bundleConfig->getLabel() ?: $bundleConfig->getBundleName());
             $objectsEntryPoint->addChildren($bundleObjectContainerEntryPoint);
             foreach ($entryPointsForThisBundle as $entryPoint) {
                 $bundleObjectContainerEntryPoint->addChildren($entryPoint);
             }
         }
         if ($bundleConfig->getObjects()) {
             foreach ($bundleConfig->getObjects() as $object) {
                 //setup addEntrypoint, editEntrypoint, listEntrypoint if not set already
                 if (isset($objectEntryPoints[$object->getKey()]['combine'])) {
                     if (!$object->getAddEntryPoint()) {
                         $object->setAddEntryPoint($objectEntryPoints[$object->getKey()]['combine']->getFullPath());
                     }
                     if (!$object->getEditEntryPoint()) {
                         $object->setEditEntryPoint($objectEntryPoints[$object->getKey()]['combine']->getFullPath());
                     }
                     if (!$object->getListEntryPoint()) {
                         $object->setListEntryPoint($objectEntryPoints[$object->getKey()]['combine']->getFullPath());
                     }
                 }
                 if ($object->getAddEntryPoint() && isset($objectEntryPoints[$object->getKey()]['add'])) {
                     $object->setAddEntryPoint($objectEntryPoints[$object->getKey()]['add']->getFullPath());
                 }
                 if ($object->getEditEntryPoint() && isset($objectEntryPoints[$object->getKey()]['edit'])) {
                     $object->setEditEntryPoint($objectEntryPoints[$object->getKey()]['edit']->getFullPath());
                 }
                 if ($object->getListEntryPoint() && isset($objectEntryPoints[$object->getKey()]['list'])) {
                     $object->setListEntryPoint($objectEntryPoints[$object->getKey()]['list']->getFullPath());
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: RestApiLoader.php プロジェクト: jarves/jarves
 public function setupWindowRoute(EntryPoint $entryPoint)
 {
     $class = $entryPoint->getClass();
     if (!class_exists($class)) {
         throw new ClassNotFoundException(sprintf('Class `%s` not found in entryPoint `%s`', $class, $entryPoint->getFullPath()));
     }
     /** @var $importedRoutes \Symfony\Component\Routing\RouteCollection */
     $importedRoutes = $this->import($class, 'annotation');
     $classReflection = new \ReflectionClass($class);
     $objectKey = $classReflection->getDefaultProperties()['object'];
     $object = $this->jarves->getObjects()->getDefinition($objectKey);
     if (!$object) {
         throw new ObjectNotFoundException(sprintf('Object `%s` in entryPoint `%s` of class `%s` not found.', $objectKey, $entryPoint->getFullPath(), $class));
     }
     $pattern = $entryPoint->getFullPath();
     $this->addEntryPointRoutes($importedRoutes, $pattern, $object);
 }
コード例 #4
0
ファイル: BundleConfigTest.php プロジェクト: jarves/jarves
    public function testObjectFromArray()
    {
        $entryPointsArray = array(0 => array('path' => 'backend', 'label' => 'Backend access', 'children' => array(0 => array('path' => 'chooser', 'type' => 'custom', 'label' => 'Chooser', 'fullPath' => 'backend/chooser', 'title' => 'Chooser', 'id' => 'chooser'), 1 => array('path' => 'stores', 'label' => 'Stores', 'children' => array(0 => array('path' => 'languages', 'type' => 'store', 'label' => 'Language', 'fullPath' => 'backend/stores/languages', 'title' => 'Language', 'id' => 'languages'), 1 => array('path' => 'extensions', 'type' => 'store', 'class' => 'adminStoreExtensions', 'label' => 'Extensions', 'fullPath' => 'backend/stores/extensions', 'title' => 'Extensions', 'id' => 'extensions')), 'fullPath' => 'backend/stores', 'type' => 'acl', 'title' => 'Stores', 'id' => 'stores')), 'fullPath' => 'backend', 'type' => 'acl', 'title' => 'Backend access', 'id' => 'backend'), 1 => array('path' => 'dashboard', 'type' => 'custom', 'icon' => '#icon-chart-5', 'link' => 'true', 'label' => 'Dashboard', 'fullPath' => 'dashboard', 'title' => 'Dashboard', 'id' => 'dashboard'), 2 => array('path' => 'nodes', 'type' => 'combine', 'class' => 'Admin\\Controller\\Windows\\NodeCrud', 'icon' => '#icon-screen-2', 'link' => 'true', 'label' => 'Pages', 'multi' => 'true', 'children' => array(0 => array('path' => 'add', 'type' => 'custom', 'label' => 'Add pages', 'multi' => 'true', 'fullPath' => 'nodes/add', 'title' => 'Add pages', 'id' => 'add'), 1 => array('path' => 'addDomains', 'type' => 'custom', 'label' => 'Add domains', 'multi' => 'true', 'fullPath' => 'nodes/addDomains', 'title' => 'Add domains', 'id' => 'addDomains'), 2 => array('path' => 'root', 'type' => 'combine', 'class' => '\\Admin\\Controller\\Windows\\DomainCrud', 'label' => 'Domain', 'fullPath' => 'nodes/root', 'title' => 'Domain', 'id' => 'root'), 3 => array('path' => 'frontend', 'type' => 'custom', 'label' => 'Frontend', 'fullPath' => 'nodes/frontend', 'title' => 'Frontend', 'id' => 'frontend')), 'fullPath' => 'nodes', 'title' => 'Pages', 'id' => 'nodes'));
        $entryPoints = [];
        foreach ($entryPointsArray as $entryPointArray) {
            $entryPoint = new EntryPoint(null, $this->getJarves());
            $entryPoint->fromArray($entryPointArray);
            $entryPoints[] = $entryPoint;
        }
        $xmlBackend = '<entryPoint path="backend">
  <label>Backend access</label>
  <children>
    <entryPoint path="chooser" type="custom">
      <label>Chooser</label>
    </entryPoint>
    <entryPoint path="stores">
      <label>Stores</label>
      <children>
        <entryPoint path="languages" type="store">
          <label>Language</label>
        </entryPoint>
        <entryPoint path="extensions" type="store">
          <class>adminStoreExtensions</class>
          <label>Extensions</label>
        </entryPoint>
      </children>
    </entryPoint>
  </children>
</entryPoint>';
        $xmlDashboard = '<entryPoint path="dashboard" type="custom" icon="#icon-chart-5" link="true">
  <label>Dashboard</label>
</entryPoint>';
        $xmlNodes = '<entryPoint path="nodes" type="combine" icon="#icon-screen-2" link="true" multi="true">
  <class>Admin\\Controller\\Windows\\NodeCrud</class>
  <label>Pages</label>
  <children>
    <entryPoint path="add" type="custom" multi="true">
      <label>Add pages</label>
    </entryPoint>
    <entryPoint path="addDomains" type="custom" multi="true">
      <label>Add domains</label>
    </entryPoint>
    <entryPoint path="root" type="combine">
      <class>\\Admin\\Controller\\Windows\\DomainCrud</class>
      <label>Domain</label>
    </entryPoint>
    <entryPoint path="frontend" type="custom">
      <label>Frontend</label>
    </entryPoint>
  </children>
</entryPoint>';
        $this->assertEquals($xmlBackend, $entryPoints[0]->toXml());
        $this->assertEquals($xmlDashboard, $entryPoints[1]->toXml());
        $this->assertEquals($xmlNodes, $entryPoints[2]->toXml());
    }
コード例 #5
0
ファイル: Bundle.php プロジェクト: jarves/jarves
 /**
  * @param EntryPoint $entryPoint
  * @return EntryPoint[]
  */
 public function getAllEntryPoints(EntryPoint $entryPoint = null)
 {
     $entryPoints = array();
     if ($entryPoint) {
         $subEntryPoints = $entryPoint->getChildren();
     } else {
         $subEntryPoints = $this->getEntryPoints();
     }
     if (null !== $subEntryPoints) {
         foreach ($subEntryPoints as $subEntryPoint) {
             $entryPoints[$this->getBundleName() . '/' . $subEntryPoint->getFullPath()] = $subEntryPoint;
             $entryPoints = array_merge($entryPoints, $this->getAllEntryPoints($subEntryPoint));
         }
     }
     return $entryPoints;
 }