Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Add doctrine/phpcr-odm; Refactory header
Browse files Browse the repository at this point in the history
  • Loading branch information
gpupo committed May 4, 2018
1 parent 80f4900 commit f74d636
Show file tree
Hide file tree
Showing 30 changed files with 437 additions and 40 deletions.
Binary file added Resources/images/catalog/product/A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/catalog/product/B.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/catalog/product/C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/catalog/product/D.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/catalog/product/E.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/catalog/product/F.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/catalog/product/G.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Resources/jlogo.gif
Binary file not shown.
64 changes: 64 additions & 0 deletions cli-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/*
* This file is part of gpupo/jackalope-jackrabbit-by-example
* Created by Gilmar Pupo <contact@gpupo.com>
* For the information of copyright and license you should read the file
* LICENSE which is distributed with this source code.
* Para a informação dos direitos autorais e de licença você deve ler o arquivo
* LICENSE que é distribuído com este código-fonte.
* Para obtener la información de los derechos de autor y la licencia debe leer
* el archivo LICENSE que se distribuye con el código fuente.
* For more information, see <https://opensource.gpupo.com/>.
*
*/

$extraCommands = [];
$extraCommands[] = new \Jackalope\Tools\Console\Command\JackrabbitCommand();

if (!isset($argv[1])
|| 'jackalope:run:jackrabbit' === $argv[1]
|| 'list' === $argv[1]
|| 'help' === $argv[1]
) {
//abort here, do not try to init repository
return;
}

$params = [
'jackalope.jackrabbit_uri' => 'http://localhost:8080/server/',
];

$workspace = 'default';
$user = 'admin';
$pass = 'admin';

// bootstrapping the repository implementation. for jackalope, do this:
$factory = new \Jackalope\RepositoryFactoryJackrabbit();
$repository = $factory->getRepository($params);
$credentials = new \PHPCR\SimpleCredentials($user, $pass);
$session = $repository->login($credentials, $workspace);

// prepare the doctrine configuration
$config = new \Doctrine\ODM\PHPCR\Configuration();
$driver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver(
new \Doctrine\Common\Annotations\AnnotationReader(),
'vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Document'
);
$config->setMetadataDriverImpl($driver);

$dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session, $config);

$helperSet = new \Symfony\Component\Console\Helper\HelperSet([
'phpcr' => new \PHPCR\Util\Console\Helper\PhpcrHelper($session),
'phpcr_console_dumper' => new \PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper(),
'dm' => new \Doctrine\ODM\PHPCR\Tools\Console\Helper\DocumentManagerHelper(null, $dm),
]);

if (class_exists('Symfony\Component\Console\Helper\QuestionHelper')) {
$helperSet->set(new \Symfony\Component\Console\Helper\QuestionHelper(), 'question');
} else {
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"type": "project",
"require": {
"jackalope/jackalope-jackrabbit": "^1.3",
"symfony/var-dumper": "^4.0"
"symfony/var-dumper": "^4.0",
"doctrine/phpcr-odm": "^1.4",
"symfony/finder": "^4.0"
},
"license": "MIT",
"authors": [
Expand Down
43 changes: 43 additions & 0 deletions src/DoctrinePhpcrOdm/010-GettingStated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/*
* This file is part of gpupo/jackalope-jackrabbit-by-example
* Created by Gilmar Pupo <contact@gpupo.com>
* For the information of copyright and license you should read the file
* LICENSE which is distributed with this source code.
* Para a informação dos direitos autorais e de licença você deve ler o arquivo
* LICENSE que é distribuído com este código-fonte.
* Para obtener la información de los derechos de autor y la licencia debe leer
* el archivo LICENSE que se distribuye con el código fuente.
* For more information, see <https://opensource.gpupo.com/>.
*
*/

require __DIR__.'/bootstrap.php';
require __DIR__.'/Document.php';

// get the root node to add our data to it
$rootDocument = $documentManager->find(null, '/');

// create a new document
$doc = new Document();
$doc->setParent($rootDocument);
$doc->setName('doc');
$doc->setTitle('My first document');
$doc->setContent('The document content');

// create a second document
$childDocument = new Document();
$childDocument->setParent($doc);
$childDocument->setName('child');
$childDocument->setTitle('My child document');
$childDocument->setContent('The child document content');

// make the documents known to the document manager
$documentManager->persist($doc);
$documentManager->persist($childDocument);

// store all changes, insertions, etc. with the storage backend
$documentManager->flush();
37 changes: 37 additions & 0 deletions src/DoctrinePhpcrOdm/011-WritingNodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/*
* This file is part of gpupo/jackalope-jackrabbit-by-example
* Created by Gilmar Pupo <contact@gpupo.com>
* For the information of copyright and license you should read the file
* LICENSE which is distributed with this source code.
* Para a informação dos direitos autorais e de licença você deve ler o arquivo
* LICENSE que é distribuído com este código-fonte.
* Para obtener la información de los derechos de autor y la licencia debe leer
* el archivo LICENSE que se distribuye con el código fuente.
* For more information, see <https://opensource.gpupo.com/>.
*
*/

require __DIR__.'/bootstrap.php';

use Doctrine\ODM\PHPCR\Document\Generic;
use PHPCR\ItemExistsException;

$catalog = new Generic();
$catalog->setNodename('catalog');
$catalog->setParentDocument($documentManager->find(null, '/'));

$product = new Generic();
$product->setNodename('product');
$product->setParentDocument($catalog);

try {
$documentManager->persist($catalog);
$documentManager->persist($product);
$documentManager->flush();
} catch (ItemExistsException $e) {
echo sprintf("Warning: %s \n", $e->getMessage());
}
42 changes: 42 additions & 0 deletions src/DoctrinePhpcrOdm/012-WritingImages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/*
* This file is part of gpupo/jackalope-jackrabbit-by-example
* Created by Gilmar Pupo <contact@gpupo.com>
* For the information of copyright and license you should read the file
* LICENSE which is distributed with this source code.
* Para a informação dos direitos autorais e de licença você deve ler o arquivo
* LICENSE que é distribuído com este código-fonte.
* Para obtener la información de los derechos de autor y la licencia debe leer
* el archivo LICENSE que se distribuye con el código fuente.
* For more information, see <https://opensource.gpupo.com/>.
*
*/

require __DIR__.'/bootstrap.php';

use Doctrine\ODM\PHPCR\Document\File;
use Symfony\Component\Finder\Finder;

$parentDocument = $documentManager->find(null, '/catalog/product');

$finder = new Finder();
$finder->files()->name('*.jpg')->in(dirname(__FILE__, 3).'/Resources/images/catalog/product/');

foreach ($finder as $f) {
$file = new File();
$file->setFileContentFromFilesystem($f->getRealPath());
$nodeName = $f->getRelativePathname();

if ($documentManager->find(null, '/catalog/product/'.$nodeName)) {
echo sprintf("Node %s already exists\n", $nodeName);
} else {
$file->setNodename($nodeName);
$file->setParentDocument($parentDocument);
echo sprintf("Saving node %s \n", $nodeName);
$documentManager->persist($file);
$documentManager->flush();
}
}
52 changes: 52 additions & 0 deletions src/DoctrinePhpcrOdm/013-ReadingImages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/*
* This file is part of gpupo/jackalope-jackrabbit-by-example
* Created by Gilmar Pupo <contact@gpupo.com>
* For the information of copyright and license you should read the file
* LICENSE which is distributed with this source code.
* Para a informação dos direitos autorais e de licença você deve ler o arquivo
* LICENSE que é distribuído com este código-fonte.
* Para obtener la información de los derechos de autor y la licencia debe leer
* el archivo LICENSE que se distribuye con el código fuente.
* For more information, see <https://opensource.gpupo.com/>.
*
*/

require __DIR__.'/bootstrap.php';

use Doctrine\ODM\PHPCR\Document\File;
use Symfony\Component\Finder\Finder;

$finder = new Finder();
$finder->files()->name('*.jpg')->in(dirname(__FILE__, 3).'/Resources/images/catalog/product/');

foreach ($finder as $f) {
$nodeName = $f->getRelativePathname();
$file = $documentManager->find(null, '/catalog/product/'.$nodeName);
$content = $file->getContent();
$data = $content->getData();

echo sprintf("\nImage %s:\n\tSize in jackrabbit is %d bytes and %d in local filesystem\n", $nodeName, $content->getSize(), $f->getSize());

foreach (['MimeType', 'Encoding', 'LastModified', 'LastModifiedBy', 'Mime'] as $prop) {
$method = 'get'.$prop;
$value = $content->{$method}();

if ($value instanceof \DateTime) {
$value = $value->format('Y-m-d H:i:s');
}
echo sprintf("\r\t\$content->%s() delivery %s: [%s]\n", $method, $prop, $value);
}

echo sprintf("\r\t** \$file->getContent() is a %s class\n", get_class($content));
echo sprintf("\r\t** \$file->getContent()->getData() is a %s class\n", $data);

$temporaryImageFilename = sprintf('%s/var/image-fetched-from-jackrabbit-%s', dirname(__FILE__, 3), $nodeName);
file_put_contents($temporaryImageFilename, $file->getFileContent());
echo sprintf("\r\t** Image saved at %s\n", $temporaryImageFilename);

echo "\n-------\n";
}
94 changes: 94 additions & 0 deletions src/DoctrinePhpcrOdm/Document.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

/*
* This file is part of gpupo/jackalope-jackrabbit-by-example
* Created by Gilmar Pupo <contact@gpupo.com>
* For the information of copyright and license you should read the file
* LICENSE which is distributed with this source code.
* Para a informação dos direitos autorais e de licença você deve ler o arquivo
* LICENSE que é distribuído com este código-fonte.
* Para obtener la información de los derechos de autor y la licencia debe leer
* el archivo LICENSE que se distribuye con el código fuente.
* For more information, see <https://opensource.gpupo.com/>.
*
*/

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;

/**
* @PHPCR\Document
*/
class Document
{
/**
* @PHPCR\Id
*/
private $id;

/**
* @PHPCR\ParentDocument
*/
private $parent;

/**
* @PHPCR\Nodename
*/
private $name;

/**
* @PHPCR\Children
*/
private $children;

/**
* @PHPCR\Field(type="string")
*/
private $title;

/**
* @PHPCR\Field(type="string")
*/
private $content;

public function getId()
{
return $this->id;
}

public function getChildren()
{
return $this->children;
}

public function setParent($parent)
{
$this->parent = $parent;
}

public function setName($name)
{
$this->name = $name;
}

public function setTitle($title)
{
$this->title = $title;
}

public function getTitle()
{
return $this->title;
}

public function setContent($content)
{
$this->content = $content;
}

public function getContent()
{
return $this->content;
}
}
Loading

0 comments on commit f74d636

Please sign in to comment.