This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add doctrine/phpcr-odm; Refactory header
- Loading branch information
Showing
30 changed files
with
437 additions
and
40 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.