Jackalope\Item::__construct PHP Method

__construct() protected method

Initialize basic information common to nodes and properties
protected __construct ( jackalope\FactoryInterface $factory, string $path, jackalope\Session $session, ObjectManager $objectManager, boolean $new = false )
$factory jackalope\FactoryInterface the object factory
$path string The normalized and absolute path to this item
$session jackalope\Session
$objectManager ObjectManager
$new boolean can be set to true to tell the object that it has been created locally
    protected function __construct(FactoryInterface $factory, $path, Session $session, ObjectManager $objectManager, $new = false)
    {
        $this->factory = $factory;
        $this->valueConverter = $this->factory->get('PHPCR\\Util\\ValueConverter');
        $this->session = $session;
        $this->objectManager = $objectManager;
        $this->setState($new ? self::STATE_NEW : self::STATE_CLEAN);
        if (!$new && $session->getRepository()->getDescriptor(RepositoryInterface::OPTION_TRANSACTIONS_SUPPORTED) && $session->getWorkspace()->getTransactionManager()->inTransaction()) {
            // properly set previous state in case we get into a rollback
            $this->savedState = self::STATE_CLEAN;
        }
        $this->setPath($path);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Create a new node item.
  *
  * Parameters are identical to \jackalope\Item
  *
  * @param array $rawData TODO: document the format of this
  */
 public function __construct($factory, $rawData, $path, $session, $objectManager, $new = false)
 {
     parent::__construct($factory, $path, $session, $objectManager, $new);
     $this->isNode = true;
     //TODO: determine the index if != 1
     foreach ($rawData as $key => $value) {
         if (is_object($value)) {
             $this->nodes[] = $key;
         } else {
             // It's probably a property type
             if (0 === strpos($key, ':')) {
                 // It's a binary property and we just got its length
                 if (is_int($value)) {
                     $key = substr($key, 1);
                     $this->properties[$key] = $this->factory->get('Property', array(array('type' => \PHPCR\PropertyType::BINARY, 'value' => (string) $value), $this->getChildPath($key), $this->session, $this->objectManager));
                 }
                 continue;
             }
             switch ($key) {
                 case 'jcr:index':
                     $this->index = $value;
                     break;
                 case 'jcr:primaryType':
                     $this->primaryType = $value;
                     $this->properties[$key] = $this->factory->get('Property', array(array('type' => \PHPCR\PropertyType::NAME, 'value' => $value), $this->getChildPath('jcr:primaryType'), $this->session, $this->objectManager));
                     break;
                 case 'jcr:mixinTypes':
                     $this->properties[$key] = $this->factory->get('Property', array(array('type' => \PHPCR\PropertyType::NAME, 'value' => $value), $this->getChildPath($key), $this->session, $this->objectManager));
                     break;
                 case 'jcr:uuid':
                     $this->uuid = $value;
                     break;
                     //TODO: more special information?
                     //OPTIMIZE: do not instantiate properties unless needed
                 //TODO: more special information?
                 //OPTIMIZE: do not instantiate properties unless needed
                 default:
                     //TODO: if we create node locally, $rawData might be a plain array. So far this is not triggered, but its a bit flaky
                     // parsing of types done according to: http://jackrabbit.apache.org/api/2.1/org/apache/jackrabbit/server/remoting/davex/JcrRemotingServlet.html
                     $type = isset($rawData->{':' . $key}) ? $rawData->{':' . $key} : Helper::determineType(is_array($value) ? reset($value) : $value);
                     $this->properties[$key] = $this->factory->get('Property', array(array('type' => $type, 'value' => $value), $this->getChildPath($key), $this->session, $this->objectManager));
                     break;
             }
         }
     }
 }
All Usage Examples Of Jackalope\Item::__construct