partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit ec4a076508c89bd682b661dd209a934aa0d17197
parent 8ebeab6b054cae7e8f83e5e2aadeea1ef8fa350f
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 28 Sep 2015 20:09:02 +0200

Removed obsolete code

Diffstat:
Dsrc/backend/PartKeepr/Category/Exceptions/CategoryNotFoundException.php | 16----------------
Dsrc/backend/PartKeepr/Console/Commands/DescribeCallCommand.php | 127-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Console/Commands/DescribeTypeCommand.php | 71-----------------------------------------------------------------------
Dsrc/backend/PartKeepr/Console/Commands/Exceptions/ServiceCallNotFoundException.php | 8--------
Dsrc/backend/PartKeepr/Console/Commands/Exceptions/ServiceNotFoundException.php | 8--------
Dsrc/backend/PartKeepr/Console/Commands/ListCallsCommand.php | 74--------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Console/Commands/ListServicesCommand.php | 65-----------------------------------------------------------------
Dsrc/backend/PartKeepr/Console/Commands/MinifyJSCommand.php | 273-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/EventNotification/Event.php | 69---------------------------------------------------------------------
Dsrc/backend/PartKeepr/EventNotification/EventManager.php | 43-------------------------------------------
Dsrc/backend/PartKeepr/EventNotification/EventNotificationService.php | 75---------------------------------------------------------------------------
Dsrc/backend/PartKeepr/EventNotification/LastNotification.php | 67-------------------------------------------------------------------
Dsrc/backend/PartKeepr/EventNotification/LastNotificationManager.php | 64----------------------------------------------------------------
Dsrc/backend/PartKeepr/Ping/PingService.php | 20--------------------
Dsrc/backend/PartKeepr/ProjectReport/ProjectReportService.php | 98-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/REST/ApplicationController.php | 42------------------------------------------
Dsrc/backend/PartKeepr/REST/Model.php | 71-----------------------------------------------------------------------
Dsrc/backend/PartKeepr/REST/Request.php | 122-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/REST/Response.php | 21---------------------
Dsrc/backend/PartKeepr/Session/Exceptions/SessionNotFoundException.php | 11-----------
Dsrc/backend/PartKeepr/Session/Session.php | 73-------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Session/SessionManager.php | 69---------------------------------------------------------------------
22 files changed, 0 insertions(+), 1487 deletions(-)

diff --git a/src/backend/PartKeepr/Category/Exceptions/CategoryNotFoundException.php b/src/backend/PartKeepr/Category/Exceptions/CategoryNotFoundException.php @@ -1,15 +0,0 @@ -<?php -namespace PartKeepr\Category\Exceptions; - -use PartKeepr\Util\SerializableException, - PartKeepr\PartKeepr; - -/** - * Thrown when the requested category was not found. - */ -class CategoryNotFoundException extends SerializableException { - public function __construct ($id) { - parent::__construct(sprintf(PartKeepr::i18n("Category %d not found."), $id)); - } -} -?>- \ No newline at end of file diff --git a/src/backend/PartKeepr/Console/Commands/DescribeCallCommand.php b/src/backend/PartKeepr/Console/Commands/DescribeCallCommand.php @@ -1,127 +0,0 @@ -<?php -namespace PartKeepr\Console\Commands; - -use Symfony\Component\Console\Input\InputArgument, - Symfony\Component\Console\Input\InputOption, - Symfony\Component\Console, - PartKeepr\Service\ServiceManager, - PartKeepr\Service\ServiceReflector, - PartKeepr\Service\ServiceCallReflector, - PartKeepr\Util\TablePrinter, - PartKeepr\Console\Commands\Exceptions\ServiceCallNotFoundException; - - -/** - * Implements the api-describe-call command. - */ -class DescribeCallCommand extends Console\Command\Command -{ - - /** - * Configures the api-describe-call command. - * @see Console\Command\Command - */ - protected function configure() - { - $this - ->setName('partkeepr:api-describe-call') - ->addArgument("service", InputArgument::REQUIRED, "The service") - ->addArgument("call", InputArgument::REQUIRED, "The call to describe") - ->setDescription('Describes a specific API call') - ->setHelp(<<<EOT -Describes a specific API call. Lists the parameters and return values -EOT - ); - } - - /** - * Describes a specific call. - * - * @param Console\Input\InputInterface $input The input interface - * @param Console\Output\OutputInterface $output The output interface - * @throws PartKeepr\Console\Commands\Exceptions\ServiceCallNotFoundException If the call was not found in the service - * @see Console\Command\Command - */ - protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) - { - $service = $input->getArgument("service"); - - if (substr($service, -7) == "Service") { - $service = substr($service, 0, strlen($service) - 7); - } - - $className = "PartKeepr\\".$service."\\".$service."Service"; - - if (!class_exists($className)) { - throw new \Exception(sprintf("The service %s doesn't exist", $service)); - } - - $reflector = new ServiceReflector($className); - - $call = $reflector->getCall($input->getArgument("call")); - - if (!($call instanceof \PartKeepr\Service\ServiceCallReflector)) { - throw new ServiceCallNotFoundException(sprintf("The call %s was not found in the service %s", $input->getArgument("call"), $service)); - } - - $output->writeln(sprintf("<info>%s:%s</info>: %s", $service, $input->getArgument("call"), $call->getDescription())); - $output->writeln(""); - $output->writeln($call->getDocumentation()); - $output->writeln(""); - $this->outputParameterTable($call, $output); - $output->writeln(""); - $this->outputReturnedValuesTable($call, $output); - - } - - /** - * Outputs the returned parameter table - * - * @param \PartKeepr\Service\ServiceCallReflector $call The reflected call - * @param \Symfony\Component\Console\Output\OutputInterface $output The output interface - */ - private function outputReturnedValuesTable (ServiceCallReflector $call, Console\Output\OutputInterface $output) { - $output->writeln("<info>Returned values:</info>"); - $head = array('Name', 'Type', 'Description'); - - $returnValueTable = array(); - - foreach ($call->getReturnValues() as $returnValue) { - $returnValueTable[] = array($returnValue->getName(), - $returnValue->getType(), - $returnValue->getDescription()); - } - - $table = new TablePrinter($output); - $table->setHeader($head); - $table->setBody($returnValueTable); - - $table->output(); - } - - /** - * Outputs the parameter table - * - * @param \PartKeepr\Service\ServiceCallReflector $call The reflected call - * @param \Symfony\Component\Console\Output\OutputInterface $output The output interface - */ - private function outputParameterTable (ServiceCallReflector $call, Console\Output\OutputInterface $output) { - $output->writeln("<info>Parameters:</info>"); - $head = array('Name', 'Required', 'Type', 'Description'); - - $parameterTable = array(); - - foreach ($call->getParameters() as $parameter) { - $parameterTable[] = array($parameter->getName(), - $parameter->getRequiredFlag() ? 'Yes' : 'No', - $parameter->getType(), - $parameter->getDescription()); - } - - $table = new TablePrinter($output); - $table->setHeader($head); - $table->setBody($parameterTable); - - $table->output(); - } -} diff --git a/src/backend/PartKeepr/Console/Commands/DescribeTypeCommand.php b/src/backend/PartKeepr/Console/Commands/DescribeTypeCommand.php @@ -1,71 +0,0 @@ -<?php -namespace PartKeepr\Console\Commands; - -use Symfony\Component\Console\Input\InputArgument, - Symfony\Component\Console\Input\InputOption, - Symfony\Component\Console, - PartKeepr\Service\ServiceManager, - PartKeepr\Service\TypeReflector, - PartKeepr\Util\TablePrinter; - -/** - * Implements the api-describe-type command. - */ -class DescribeTypeCommand extends Console\Command\Command -{ - - /** - * Configures the api-describe-type command. - * @see Console\Command\Command - */ - protected function configure() - { - $this - ->setName('partkeepr:api-describe-type') - ->addArgument("type", InputArgument::REQUIRED, "The type to describe") - ->setDescription('Describes a specific API type') - ->setHelp(<<<EOT -Describes a specific API type -EOT - ); - } - - /** - * Describes a specific API type. - * - * @param Console\Input\InputInterface $input The input interface - * @param Console\Output\OutputInterface $output The output interface - * @throws PartKeepr\Console\Commands\Exceptions\ServiceCallNotFoundException If the call was not found in the service - * @see Console\Command\Command - */ - protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) - { - $type = $input->getArgument("type"); - - $className = "PartKeepr\\".$type."\\".$type; - - $reflector = new TypeReflector($className); - - $output->writeln(sprintf("<info>%s</info>: %s", $reflector->getName(), $reflector->getDescription())); - $output->writeln(""); - $output->writeln($reflector->getDocumentation()); - $output->writeln(""); - $output->writeln("<info>Output Fields:</info>"); - - $head = array('Name', 'Type', 'Description'); - $outputParameterTable = array(); - foreach ($reflector->getOutputFields() as $parameter) { - $outputParameterTable[] = array($parameter->getName(), - $parameter->getType(), - $parameter->getDescription()); - } - - $table = new TablePrinter($output); - $table->setHeader($head); - $table->setBody($outputParameterTable); - - $table->output(); - - - } -} diff --git a/src/backend/PartKeepr/Console/Commands/Exceptions/ServiceCallNotFoundException.php b/src/backend/PartKeepr/Console/Commands/Exceptions/ServiceCallNotFoundException.php @@ -1,7 +0,0 @@ -<?php -namespace PartKeepr\Console\Commands\Exceptions; - -/** - * Thrown if a service call was not found in a specific service - */ -class ServiceCallNotFoundException extends \Exception {}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Console/Commands/Exceptions/ServiceNotFoundException.php b/src/backend/PartKeepr/Console/Commands/Exceptions/ServiceNotFoundException.php @@ -1,7 +0,0 @@ -<?php -namespace PartKeepr\Console\Commands\Exceptions; - -/** - * Thrown if a service was not found - */ -class ServiceNotFoundException extends \Exception {}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Console/Commands/ListCallsCommand.php b/src/backend/PartKeepr/Console/Commands/ListCallsCommand.php @@ -1,74 +0,0 @@ -<?php -namespace PartKeepr\Console\Commands; - -use Symfony\Component\Console\Input\InputArgument, - Symfony\Component\Console\Input\InputOption, - Symfony\Component\Console, - PartKeepr\Service\ServiceManager, - PartKeepr\Service\ServiceReflector, - PartKeepr\Console\Commands\Exceptions\ServiceNotFoundException; - -/** - * Implements the api-list-calls command. - */ -class ListCallsCommand extends Console\Command\Command -{ - - /** - * Configures the api-list-calls command. - * @see Console\Command\Command - */ - protected function configure() - { - $this - ->setName('partkeepr:api-list-calls') - ->addArgument("service", InputArgument::REQUIRED, "The service to list the calls for") - ->setDescription('Lists all calls within the specified service') - ->setHelp(<<<EOT -Lists all calls within the specified service -EOT - ); - } - - /** - * Lists all API calls for a specific service - * - * @param Console\Input\InputInterface $input The input interface - * @param Console\Output\OutputInterface $output The output interface - * @throws PartKeepr\Console\Commands\Exceptions\ServiceNotFoundException If the call was not found in the service - * @see Console\Command\Command - */ - protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) - { - $service = $input->getArgument("service"); - - if (substr($service, -7) == "Service") { - $service = substr($service, 0, strlen($service) - 7); - } - - $className = "PartKeepr\\".$service."\\".$service."Service"; - - if (!class_exists($className)) { - throw new ServiceNotFoundException(sprintf("The service %s doesn't exist", $service)); - } - - $reflector = new ServiceReflector($className); - - // Stores the maximum length, for nice console formatting - $maxLength = 0; - - foreach ($reflector->getCalls() as $call) { - if (strlen($call->getName()) > $maxLength) { - $maxLength = strlen($call->getName()); - } - } - - $output->writeln(sprintf("<comment>Calls for service <info>%s</info>:</comment>", $reflector->getName())); - $output->writeln(""); - - foreach ($reflector->getCalls() as $call) { - $name = str_pad($call->getName(), $maxLength); - $output->writeln(sprintf("<info>%s</info> %s", $name, $call->getDescription())); - } - } -} diff --git a/src/backend/PartKeepr/Console/Commands/ListServicesCommand.php b/src/backend/PartKeepr/Console/Commands/ListServicesCommand.php @@ -1,65 +0,0 @@ -<?php -namespace PartKeepr\Console\Commands; - -use Symfony\Component\Console\Input\InputArgument, - Symfony\Component\Console\Input\InputOption, - Symfony\Component\Console, - PartKeepr\Service\ServiceManager, - PartKeepr\Service\ServiceReflector; - -/** - * Implements the api-list-services command. - */ -class ListServicesCommand extends Console\Command\Command -{ - - /** - * Configures the api-list-services command. - * - * @see Console\Command\Command - */ - protected function configure() - { - $this - ->setName('partkeepr:api-list-services') - ->setDescription('Lists all available API services') - ->setHelp(<<<EOT -Lists all available API services defined by PartKeepr. -EOT - ); - } - - /** - * Lists all API services - * - * @param Console\Input\InputInterface $input The input interface - * @param Console\Output\OutputInterface $output The output interface - * @see Console\Command\Command - */ - protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) - { - $classNames = ServiceManager::getInstance()->getRegisteredServices(); - - $services = array(); - // Stores the maximum length, for nice console formatting - $maxLength = 0; - - foreach ($classNames as $className) { - $reflector = new ServiceReflector($className); - - if (strlen($reflector->getName()) > $maxLength) { - $maxLength = strlen($reflector->getName()); - } - - $services[] = $reflector; - } - - $output->writeln("<comment>PartKeepr Services:</comment>"); - $output->writeln(""); - - foreach ($services as $service) { - $name = str_pad($service->getName(), $maxLength); - $output->writeln(sprintf("<info>%s</info> %s", $name, $service->getDescription())); - } - } -} diff --git a/src/backend/PartKeepr/Console/Commands/MinifyJSCommand.php b/src/backend/PartKeepr/Console/Commands/MinifyJSCommand.php @@ -1,273 +0,0 @@ -<?php -namespace PartKeepr\Console\Commands; - -use Symfony\Component\Console\Input\InputArgument, - Symfony\Component\Console\Input\InputOption, - Symfony\Component\Console, - PartKeepr\PartKeepr, - PartKeepr\Util\Minifier\Minifier, - PartKeepr\Util\Minifier\jsminMinifier, - PartKeepr\Util\Minifier\yuiCompressorMinifier, - PartKeepr\Util\ExtJSFile; - -class MinifyJSCommand extends Console\Command\Command -{ - - /** - * @see Console\Command\Command - */ - protected function configure() - { - $this - ->setName('partkeepr:js-minify') - ->addArgument("outputFile", InputArgument::REQUIRED, "Output file") - ->addOption('source', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, - 'The input path(s). <info>You may specify this more than once to cover all source ' . - 'directories.</info>') - ->addOption('minifier', null, InputOption::VALUE_OPTIONAL, - 'The minifier to use. Currently <info>jsmin</info> and <info>yui-compressor</info> are ' . - 'supported.') - ->addOption('compress', null, InputOption::VALUE_NONE, - 'Specifies if compression should be used (reduces local variables, only supported by ' . - 'yui-compressor). <info>--compress</info> also includes <info>--minify</info>') - ->addOption('minify', null, InputOption::VALUE_NONE, - 'Specifies if the files should be minified (removal of whitespaces and line breaks). If not ' . - 'specified, this only merges the JS files.') - ->setDescription('Minifies JavaScript files in their correct order') - ->setHelp(<<<EOT -Minifies JavaScript files in their correct order. To do this correctly, we parse all JavaScript files and look for the ExtJS-specific 'extend' directives. With that information, -we can build a hierarchical tree of files which represent the dependencies and output a parsed tree. That tree is then converted into an ordered list, which is then compressed. -EOT - ); - } - - /** - * Executes the minify process - * - * @see Console\Command\Command - */ - protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) - { - $sourceDirs = $input->getOption('source'); - - if (count($sourceDirs) == 0) { - throw new \RuntimeException("Argument 'source' is required at least once in order to execute this command correctly."); - } - - $orderedFileList = $this->getOrderedFileList($sourceDirs); - - // Write out the used JS files which are required for the full debug frontend mode. - // @todo Fix that some time - it's a bit ugly. - - $frontendFiles = array(); - - foreach ($orderedFileList as $orderedFile) { - $orderedFile = str_replace(PartKeepr::getRootDirectory()."/src/frontend/", "", $orderedFile); - $orderedFile = str_replace(PartKeepr::getRootDirectory()."/3rdparty/extjs/examples/ux/", "js/Ext.ux/", $orderedFile); - $orderedFile = str_replace(PartKeepr::getRootDirectory()."/3rdparty/ext-wizard/Ext.ux.Wizard/", "js/Ext.ux/", $orderedFile); - $orderedFile = str_replace(PartKeepr::getRootDirectory()."/3rdparty/Ext.ux.Exporter/", "js/Ext.ux.Exporter/", $orderedFile); - - $frontendFiles[] = $orderedFile; - } - file_put_contents( - PartKeepr::getRootDirectory() . "/partkeepr.jsfiles", - serialize($frontendFiles)); - - if (count($orderedFileList) == 0) { - throw new \RuntimeException("No files in the source directories found."); - } - - switch ($input->getOption("minifier")) { - case "jsmin": - $minifier = new jsminMinifier(); - break; - case "yui-compressor": - $minifier = new yuiCompressorMinifier(); - break; - default: - $minifier = $this->detectMinifier(); - break; - } - - $minifier->setOutput($output); - - if ($input->getOption("compress") === true) { - return $minifier->compress($orderedFileList, $input->getArgument("outputFile")); - } - - if ($input->getOption("minify") === true) { - return $minifier->compress($orderedFileList, $input->getArgument("outputFile")); - } - - return $minifier->combine($orderedFileList, $input->getArgument("outputFile")); - } - - /** - * Returns an ordered file list of all source files - * - * @param $sourceDirs array The directories to scan - * @return array An array of ordered JS files - */ - protected function getOrderedFileList(array $sourceDirs) - { - $sourceDirs = $this->verifySourceDirs($sourceDirs); - $sourceFiles = $this->getSourceFiles($sourceDirs); - - $rootList = $this->buildExtJSClassTree($sourceFiles); - - $orderedFileList = array(); - - foreach ($rootList as $item) { - $orderedFileList = array_merge($orderedFileList, $item->getArray()); - } - - return $orderedFileList; - } - - /** - * Detects the minifier to use. - * - * @return string jsmin or yui-compressor - */ - protected function detectMinifier() - { - if (yuiCompressorMinifier::getYuiCompressorPath() === false) { - return new jsMinMinifier(); - } else { - return new yuiCompressorMinifier(); - } - } - - - /** - * Verifies the given source directories if they exist. - * @param $sourceDirs array An array of source directories - * @return array An array of checked and absolute source directories - * @throws \RuntimeException If the source directory can't be found - */ - protected function verifySourceDirs(array $sourceDirs) - { - $realSourcePaths = array(); - - foreach ($sourceDirs as $dir) { - $realpath = realpath($dir); - - if ($realpath === false) { - throw new \RuntimeException(sprintf("The source directory %s can't be found", $dir)); - } - - $realSourcePaths [] = $realpath; - } - - return $realSourcePaths; - } - - /** - * Returns a list of all JavaScript files in the given source directories - * @param $sourceDirs An array of source directories - * @return array An array of JavaScript files - */ - protected function getSourceFiles($sourceDirs) - { - $sourceFiles = array(); - - foreach ($sourceDirs as $dir) { - $sourceFiles = array_merge($sourceFiles, $this->getJSFilesForPath($dir)); - } - - return $sourceFiles; - } - - /** - * Builds the ExtJS class tree - * - * @param $files array A list of JavaScript files - * @return array An array of root classes (=classes which don't have other dependencies) - * @throws \Exception - */ - protected function buildExtJSClassTree(array $files) - { - $specialFiles = array( - "src/frontend/js/Util/i18n.js", - "src/frontend/js/PartKeepr.js", - "src/frontend/js/Util/JsonWithAssociationsWriter.js"); - - $records = array(); - - /* Generate class objects out of the source files */ - foreach ($files as $file) { - $file = realpath($file); - - $o = new ExtJSFile($file); - - $records[$o->getClassName()] = $o; - } - - // rootList contains all classes which have no dependencies or external dependencies. - $rootList = array(); - - /* Iterate through the array and build the dependency tree */ - foreach ($records as $record) { - $bHasRequires = false; - - foreach ($record->getRequires() as $require) { - if (stripos($require, "Ext.") === false || stripos($require, "Ext.ux") !== false) { - - /* As PartKeepr is an application and not a class (in terms of this builder), we can't find it. Skip. */ - if ($require == "PartKeepr" || $require == "Object") { - break; - } - - /* If the parser can't find the class, throw an exception */ - if (!array_key_exists($require, $records)) { - throw new \Exception("Fatal: The class in " . $record->getFilename() . " requires the class $require, but the required class isn't in the index."); - } - - $records[$require]->addChild($record); - $bHasRequires = true; - } - } - - if (!$bHasRequires) { - /* Hardcoded check for special files, as it isn't a class but a script, and needs to put in front of everything */ - $unshift = false; - - foreach ($specialFiles as $specialFile) { - // Check if the rightermost part of the filename matches our specialFile patterns - if (strrpos($record->getFilename(), $specialFile) === strlen($record->getFilename()) - strlen($specialFile)) { - $unshift = true; - } - } - if ($unshift) { - array_unshift($rootList, $record); - } else { - $rootList[] = $record; - } - } - - } - - return $rootList; - } - - /** - * Returns a list of all .js files in the given path. - * - * @param $path string The path to search - * @return array A flat array of all .js files - */ - protected function getJSFilesForPath($path) - { - if (is_dir($path)) { - $call = 'find ' . $path . ' -name "*.js" -type f'; - exec($call, $output); - return $output; - } - - if (is_file($path)) { - return array($path); - } - - return array(); - } -} diff --git a/src/backend/PartKeepr/EventNotification/Event.php b/src/backend/PartKeepr/EventNotification/Event.php @@ -1,68 +0,0 @@ -<?php -namespace PartKeepr\EventNotification; - -use PartKeepr\Util\BaseEntity, Doctrine\ORM\Mapping as ORM; - -/** - * The event notification conecpt implements the main concept of notifying a - * client on a special event he has registered for. - * The EventNotification is used to carry events from one request to a - * process which is polling for this event using a long poll or a complete - * different kind of service (like a Websocket if possible). - * - * The Event class itself represents a type of event we - * can signal. - * - * @ORM\Entity - */ -class Event extends BaseEntity{ - /** - * Name of the event - * @ORM\Column(length=64,unique=true) - * @var string - */ - private $name; - - /** - * This is a counter which counts up, everytime the event is issued. - * @ORM\Column(type="datetime") - * @var datetime - */ - private $lastOccured; - - public function __construct( $name ){ - $this->name = $name; - $this->lastOccured = new \DateTime("now"); - } - - /** - * Sets the event name. - * @param unknown $name - */ - public function setName( $name ){ - $this->name = $name; - } - - /** - * Retrieves the event name. - * @return string - */ - public function getName(){ - return $this->name; - } - - /** - * Sets the event to be emitted now. - */ - public function emit(){ - $this->lastOccured = new \DateTime("now"); - } - - /** - * Retrieve the timestamp this event has occured. - */ - public function getLastOccured(){ - return $this->lastOccured; - } - -} - \ No newline at end of file diff --git a/src/backend/PartKeepr/EventNotification/EventManager.php b/src/backend/PartKeepr/EventNotification/EventManager.php @@ -1,43 +0,0 @@ -<?php -namespace PartKeepr\EventNotification; - -use PartKeepr\Util\Exceptions\ObjectNotFoundException; - -use PartKeepr\EventNotification\Event; -use PartKeepr\PartKeepr; -use PartKeepr\Util\Singleton; - -/** - * This is a manager class for working with the event system. This manager - * is responsible for the Event. - * - */ -class EventManager extends Singleton{ - /** - * Retrieve an event by name. If the entity does not exists, one will - * be created. - * @param string $name Name of the event - */ - public function getOrCreateByName( $name ){ - $obj = PartKeepr::getEM()->getRepository('PartKeepr\EventNotification\Event')->findOneByName($name); - if (!$obj){ - $obj = new Event( $name ); - PartKeepr::getEM()->persist($obj); - PartKeepr::getEM()->flush(); - } - - return $obj; - } - - /** - * Gets an existing event by its name. - * @param unknown $name - */ - public function getByName( $name ){ - $obj = PartKeepr::getEM()->getRepository('PartKeepr\EventNotification\Event')->findOneByName($name); - if (!$obj){ - throw new ObjectNotFoundException('PartKeepr\EventNotification\Event', "name=$name"); - } - return $obj; - } -} diff --git a/src/backend/PartKeepr/EventNotification/EventNotificationService.php b/src/backend/PartKeepr/EventNotification/EventNotificationService.php @@ -1,74 +0,0 @@ -<?php -namespace PartKeepr\EventNotification; - -use PartKeepr\Service\Service; -use PartKeepr\EventNotification\LastNotificationManager; - -/** - * This service can be used to register to events. This registration is - * done on aper session base and if the session is recreated all registrations - * will go away. - * Once the session has registered a listener to an event, he will be able to - * poll for occurance of this event. If this happens the user of this service - * can react on it. - */ -class EventNotificationService extends Service{ - /** - * Registers a listener to an event. - */ - public function registerListener(){ - $this->requireParameter("event"); - $eventName = $this->getParameter("event"); - - LastNotificationManager::getInstance()->startListeningToEvent( $eventName ); - return array('data'=>''); - } - - /** - * Deregisters listening to event. - */ - public function deregisterListener(){ - $this->requireParameter("event"); - $eventName = $this->getParameter("event"); - - LastNotificationManager::getInstance()->stopListeningToEvent( $eventName ); - return array('data'=>''); - } - - /** - * Check if we were notified. This method sets all events to confirmed after they - * have been sent to the user. - * - * This servcice call additional supports a long polling mechanism with the parameters: - * long: Set this to 1 to activate the long polling mode - * timeout: Optional, use this to define a user defined timeout if a shortre timeout - * than the default timeout is needed. - */ - public function isNotified(){ - $longPollingMode = $this->getParameter("long",false); - - // The maximum time we will try to fetch a notify until we will return. - // For correct usage, also have a look at the maximum execution time. - $maxTimeInSeconds = max( $this->getParameter("timeout",15), 15 ); - - $listeners = array(); - - $time_start = microtime(true); - do - { - $listeners = LastNotificationManager::getInstance()->getNotifiedListeners(); - usleep(250000); - }while( $longPollingMode !== false - && count( $listeners ) == 0 - && (microtime(true) - $time_start) < $maxTimeInSeconds ); - - $data = array(); - - foreach( $listeners as $listener ){ - $data[] = $listener->getEvent()->getName(); - $listener->confirm(); - } - - return array('data'=> $data); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/EventNotification/LastNotification.php b/src/backend/PartKeepr/EventNotification/LastNotification.php @@ -1,67 +0,0 @@ -<?php -namespace PartKeepr\EventNotification; - -use PartKeepr\EventNotification\Event; -use PartKeepr\Session\Session; -use PartKeepr\Util\BaseEntity; -use Doctrine\ORM\Mapping as ORM; - - -/** - * This entity is used to store the last notification of - * an event. - * - * @ORM\Entity - */ -class LastNotification extends BaseEntity{ - /** - * This is the associated event. - * @ORM\ManyToOne(targetEntity="PartKeepr\EventNotification\Event") - */ - private $event; - - /** - * @ORM\ManyToOne(targetEntity="PartKeepr\Session\Session") - * @ORM\JoinColumn(onDelete="CASCADE") - */ - private $session; - - /** - * This is the last timestamp, the user was notified about - * an occured event. - * - * @ORM\Column(type="datetime") - * @var datetime - */ - private $lastNotify; - - - public function __construct ( Event $event, Session $session ) { - $this->event = $event; - $this->session = $session; - $this->lastNotify = new \DateTime("now"); - } - - /** - * Checks if this class is notified by its event. - */ - public function isNotified(){ - return $lastNotify < $event->getLastOccured(); - } - - /** - * Confirms the notify and resets the notified state to false. - */ - public function confirm(){ - $this->lastNotify = new \DateTime("now"); - } - - /** - * Retrieves the event. - * @return Event - */ - public function getEvent(){ - return $this->event; - } - -} diff --git a/src/backend/PartKeepr/EventNotification/LastNotificationManager.php b/src/backend/PartKeepr/EventNotification/LastNotificationManager.php @@ -1,64 +0,0 @@ -<?php -namespace PartKeepr\EventNotification; - -use PartKeepr\EventNotification\LastNotification; -use PartKeepr\PartKeepr; -use PartKeepr\Session\SessionManager; -use PartKeepr\Util\Singleton; - -/** - * This is a manager class for working with the event system. This manager - * is responsible for the Event. - * - */ -class LastNotificationManager extends Singleton{ - /** - * Creates or retrieves a LastNotification entity by its event name. - * - * @param string $name Name of the event to retrive the record. - */ - private function getOrCreateByEventName( $name ){ - $event = EventManager::getInstance()->getByName($name); - $session = SessionManager::getCurrentSession(); - - $obj = PartKeepr::getEM()->getRepository('PartKeepr\EventNotification\LastNotification') - ->findOneBy(array('event' => $event->getId(), 'session' => $session->getId() )); - - if (!$obj){ - $obj = new LastNotification($event, $session); - PartKeepr::getEM()->persist($obj); - PartKeepr::getEM()->flush(); - } - - return $obj; - } - - /** - * Starts listeneing to the event with the given name. - */ - public function startListeningToEvent( $name ){ - $notify = $this->getOrCreateByEventName( $name ); - } - - /** - * Ends listening to the event and destroy the record of the listener. - */ - public function stopListeningToEvent( $name ){ - $notify = $this->getOrCreateByEventName( $name ); - PartKeepr::getEM()->remove($notify); - PartKeepr::getEM()->flush(); - } - - /** - * Get all entries which are notified by the event. - */ - public function getNotifiedListeners(){ - $session = SessionManager::getCurrentSession(); - $query = PartKeepr::getEM()->createQuery("SELECT l FROM PartKeepr\EventNotification\LastNotification l JOIN l.session s JOIN l.event e WHERE s.id = ?1 AND e.lastOccured > l.lastNotify"); - $query->setParameter(1,$session->getId()); - - return $query->getResult(); - } -} - - diff --git a/src/backend/PartKeepr/Ping/PingService.php b/src/backend/PartKeepr/Ping/PingService.php @@ -1,19 +0,0 @@ -<?php -namespace PartKeepr\Ping; -use PartKeepr\Service\AnonService; - -use PartKeepr\Service\Service, - PartKeepr\PartKeepr; - -class PingService extends AnonService { - /** - * Simple test call to verify if the service layer is reachable. - * - * This is used for the PartKeeprMobile client to verify if the URL - * is entered correctly. - */ - public function ping () { - return "pong"; - } - -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/ProjectReport/ProjectReportService.php b/src/backend/PartKeepr/ProjectReport/ProjectReportService.php @@ -1,97 +0,0 @@ -<?php -namespace PartKeepr\ProjectReport; - -use PartKeepr\Service\RestfulService, - PartKeepr\Service\Service, - PartKeepr\Project\ProjectManager, - PartKeepr\PartKeepr, - PartKeepr\PartBundle\Entity\Part, - PartKeepr\Manager\ManagerFilter; - -class ProjectReportService extends Service implements RestfulService { - /** - * Returns a project report. - * - * The input format is an array with the following keys per entry: - * - project: The project ID - * - amount: Specifies how many copies of the project need to be reported - * - * The output format is an array which contains the following keys: - * - quantity: The overall quantity of parts needed (for a specific part) - * - part: The serialized part entity - * - storageLocation_name: The storage location name - * - available: The overall amount of available parts - * - sum_order: Always set to 0 because calculation happens in the frontend - * - * @see PartKeepr\Service.RestfulService::get() - */ - public function get () { - $reports = json_decode($this->getParameter("reports"), true); - - $aPartResults = array(); - - // Loop over all reports and calculate the overall quantities - foreach ($reports as $report) { - $dql = "SELECT pp.quantity, pro.name AS projectname, pp.remarks, p.id FROM "; - $dql .= "PartKeepr\Project\ProjectPart pp JOIN pp.part p "; - $dql .= "JOIN pp.project pro WHERE pp.project = :project"; - - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("project", $report["project"]); - - foreach ($query->getArrayResult() as $result) { - $part = Part::loadById($result["id"]); - - if (array_key_exists($result["id"], $aPartResults)) { - // Only update the quantity of the part - $aPartResults[$result["id"]]["quantity"] += $result["quantity"] * $report["amount"]; - $aPartResults[$result["id"]]["projects"][] = $result["projectname"]; - - if ($result["remarks"] != "") { - $aPartResults[$result["id"]]["remarks"][] = $result["projectname"]. ": " .$result["remarks"]; - } - } else { - // Create a full resultset - $aPartResults[$result["id"]] = array( - "quantity" => $result["quantity"] * $report["amount"], - "part" => array("response" => array("totalCount" => 1, "data" => $part->serialize())), - "storageLocation_name" => $part->getStorageLocation()->getName(), - "available" => $part->getStockLevel(), - "sum_order" => 0, - "projects" => array($result["projectname"]), - "remarks" => array() - ); - - if ($result["remarks"] != "") { - $aPartResults[$result["id"]]["remarks"] = array($result["projectname"]. ": " .$result["remarks"]); - } - } - } - } - - $aFinalResult = array(); - - // Iterate over all results and calculate how many parts are missing - foreach ($aPartResults as $key => $partResult) { - $missing = $partResult["quantity"] - $partResult["available"]; - - if ($missing < 0) { - $missing = 0; - } - - $partResult["missing"] = $missing; - $partResult["remarks"] = implode(", ", $partResult["remarks"]); - $partResult["projects"] = implode(", ", $partResult["projects"]); - - $aFinalResult[] = $partResult; - } - - return array("data" => $aFinalResult); - } - - public function create () {} - - public function update () {} - - public function destroy () {} -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/REST/ApplicationController.php b/src/backend/PartKeepr/REST/ApplicationController.php @@ -1,42 +0,0 @@ -<?php -namespace PartKeepr\REST; - -// Class taken over from the Sencha example -class ApplicationController { - public $request, $id, $params; - - /** - * dispatch - * Dispatch request to appropriate controller-action by convention according to the HTTP method. - */ - public function dispatch($request) { - $this->request = $request; - $this->id = $request->id; - $this->params = $request->params; - - if ($request->isRestful()) { - return $this->dispatchRestful(); - } - if ($request->action) { - return $this->{$request->action}(); - } - } - - protected function dispatchRestful() { - switch ($this->request->method) { - case 'GET': - return $this->view(); - break; - case 'POST': - return $this->create(); - break; - case 'PUT': - return $this->update(); - break; - case 'DELETE': - return $this->destroy(); - break; - } - } -} - diff --git a/src/backend/PartKeepr/REST/Model.php b/src/backend/PartKeepr/REST/Model.php @@ -1,71 +0,0 @@ -<?php -namespace PartKeepr\REST; - -// Class taken over from the Sencha example -class Model { - public $id, $attributes; - static function create($params) { - $obj = new self(get_object_vars($params)); - $obj->save(); - return $obj; - } - static function find($id) { - global $dbh; - $found = null; - foreach ($dbh->rs() as $rec) { - if ($rec['id'] == $id) { - $found = new self($rec); - break; - } - } - return $found; - } - static function update($id, $params) { - global $dbh; - $rec = self::find($id); - - if ($rec == null) { - return $rec; - } - $rs = $dbh->rs(); - - foreach ($rs as $idx => $row) { - if ($row['id'] == $id) { - $rec->attributes = array_merge($rec->attributes, get_object_vars($params)); - $dbh->update($idx, $rec->attributes); - break; - } - } - return $rec; - } - static function destroy($id) { - global $dbh; - $rec = null; - $rs = $dbh->rs(); - foreach ($rs as $idx => $row) { - if ($row['id'] == $id) { - $rec = new self($dbh->destroy($idx)); - break; - } - } - return $rec; - } - static function all() { - global $dbh; - return $dbh->rs(); - } - - public function __construct($params) { - $this->id = isset($params['id']) ? $params['id'] : null; - $this->attributes = $params; - } - public function save() { - global $dbh; - $this->attributes['id'] = $dbh->pk(); - $dbh->insert($this->attributes); - } - public function to_hash() { - return $this->attributes; - } -} - diff --git a/src/backend/PartKeepr/REST/Request.php b/src/backend/PartKeepr/REST/Request.php @@ -1,122 +0,0 @@ -<?php -namespace PartKeepr\REST; - -// Class taken over from the Sencha example -class Request { - public $restful, $method, $controller, $action, $id, $params; - - public function __construct($params) { - $this->restful = (isset($params["restful"])) ? $params["restful"] : false; - $this->method = $_SERVER["REQUEST_METHOD"]; - $this->parseRequest(); - } - public function isRestful() { - return $this->restful; - } - - public function getMethod () { - return $this->method; - } - - public function getParams () { - if ($this->params === null) { - $this->params = array(); - } - - if ($this->id !== null) { - $this->params["id"] = $this->id; - } - - $this->params = array_merge($_REQUEST, $this->params); - return $this->params; - } - - public function getService () { - if ($this->controller == "") { - $this->controller = $_REQUEST["service"]; - } - - // Here we split our controller path. We got then elements: - // - The element is used for the class name too. - // - All elements will be used to build the path to the class - // Foo.Bar => PartKeepr\\Foo\\Bar\\BarService - $serviceClassPath = explode( '.', $this->controller ); - array_unshift($serviceClassPath,'PartKeepr' ); - $serviceName = end($serviceClassPath)."Service"; - reset($serviceClassPath); - array_push($serviceClassPath, $serviceName); - - $fullName = implode("\\",$serviceClassPath); - - $class = new $fullName($this->getParams()); - - return $class; - } - - public function getAction () { - return $this->action; - } - - protected function parseRequest() { - if ($this->method == 'PUT') { // <-- Have to jump through hoops to get PUT data - $raw = ''; - $httpContent = fopen('php://input', 'r'); - while ($kb = fread($httpContent, 1024)) { - $raw .= $kb; - } - fclose($httpContent); - $params = array(); - parse_str($raw, $params); - - if (isset($params['data'])) { - $this->params = json_decode($params['data'], true); - } else { - $params = json_decode($raw, true); - $this->params = $params; - } - } else { - // grab JSON data if there... - $this->params = (isset($_REQUEST['data'])) ? json_decode($_REQUEST['data'], true) : null; - - if (isset($_REQUEST['data'])) { - $this->params = json_decode($_REQUEST['data'], true); - } else { - $raw = ''; - $httpContent = fopen('php://input', 'r'); - while ($kb = fread($httpContent, 1024)) { - $raw .= $kb; - } - $params = json_decode($raw, true); - if ($params) { - $this->params = $params; - } - } - - } - // Quickndirty PATH_INFO parser - if (isset($_SERVER["PATH_INFO"])){ - $cai = '/^\/([A-Za-z.]+\w)\/([A-Za-z]+\w)\/([0-9]+)$/'; // /controller/action/id - $ca = '/^\/([A-Za-z.]+\w)\/([A-Za-z]+)$/'; // /controller/action - $ci = '/^\/([A-Za-z.]+\w)\/([0-9]+)$/'; // /controller/id - $c = '/^\/([A-Za-z.]+\w)$/'; // /controller - $i = '/^\/([0-9]+)$/'; // /id - $matches = array(); - if (preg_match($cai, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - $this->action = $matches[2]; - $this->id = $matches[3]; - } else if (preg_match($ca, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - $this->action = $matches[2]; - } else if (preg_match($ci, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - $this->id = $matches[2]; - } else if (preg_match($c, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - } else if (preg_match($i, $_SERVER["PATH_INFO"], $matches)) { - $this->id = $matches[1]; - } - } - } -} - diff --git a/src/backend/PartKeepr/REST/Response.php b/src/backend/PartKeepr/REST/Response.php @@ -1,21 +0,0 @@ -<?php -namespace PartKeepr\REST; - -// Class taken over from the Sencha example -class Response { - public $success, $data, $message, $errors, $tid, $trace; - - public function __construct($params = array()) { - $this->success = isset($params["success"]) ? $params["success"] : false; - $this->message = isset($params["message"]) ? $params["message"] : ''; - $this->data = isset($params["data"]) ? $params["data"] : array(); - } - - public function to_json() { - return json_encode(array( - 'success' => $this->success, - 'message' => $this->message, - 'data' => $this->data - )); - } -} diff --git a/src/backend/PartKeepr/Session/Exceptions/SessionNotFoundException.php b/src/backend/PartKeepr/Session/Exceptions/SessionNotFoundException.php @@ -1,10 +0,0 @@ -<?php -namespace PartKeepr\Session\Exceptions; - -use PartKeepr\Util\SerializableException; - -class SessionNotFoundException extends SerializableException { - public function __construct ($id) { - parent::__construct("The session with the id $id could not be found"); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Session/Session.php b/src/backend/PartKeepr/Session/Session.php @@ -1,72 +0,0 @@ -<?php -namespace PartKeepr\Session; - -use Doctrine\ORM\Mapping as ORM; -use PartKeepr\AuthBundle\Entity\User; -use Symfony\Component\HttpFoundation\Session\Session as SymfonySession; -use PartKeepr\PartKeepr; -use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; -/** @ORM\Entity */ -class Session { - - /** @ORM\Id @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ - private $id; - - /** @ORM\Column(length=64) */ - private $sessionid; - - /** - * @var User - * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") - */ - private $user; - - private $session; - - public function __construct () { - } - - public function start () { - $this->session = new SymfonySession(new MockFileSessionStorage()); - $this->session->start(); - $this->session->migrate(); - $this->session->invalidate(); - $this->session->start(); - - $query = PartKeepr::getEM()->createQuery("DELETE FROM PartKeepr\\Session\\Session s WHERE s.sessionid = :session"); - $query->setParameter("session", $this->session->getId()); - $query->execute(); - - $this->sessionid = $this->session->getId(); - } - - public function getId(){ - return $this->id; - } - - public function getSessionID () { - return $this->sessionid; - } - - public function resume () { - $this->session = new SymfonySession(new MockFileSessionStorage()); - $this->session->setId($this->sessionid); - $this->session->start(); - } - - /** - * Returns the user object - * -*@return \PartKeepr\AuthBundle\Entity\User - */ - public function getUser () { - return $this->user; - } - - public function setUser (User $user = null) { - $this->user = $user; - } - -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Session/SessionManager.php b/src/backend/PartKeepr/Session/SessionManager.php @@ -1,68 +0,0 @@ -<?php -namespace PartKeepr\Session; - -use PartKeepr\AuthBundle\Entity\User; -use PartKeepr\PartKeepr; -use PartKeepr\Session\Exceptions\SessionNotFoundException; -use PartKeepr\Util\Singleton; - -class SessionManager extends Singleton { - public static $currentSession = null; - - public static function getCurrentSession () { - return self::$currentSession; - } - - public static function hasSession () { - if (self::$currentSession !== null) { - return true; - } else { - return false; - } - } - - public function startSession (User $user = null) { - if (is_object($user)) { - try { - $query = PartKeepr::getEM()->createQuery("SELECT s FROM PartKeepr\\Session\\Session s WHERE s.user = :user"); - $query->setParameter("user", $user); - $query->execute(); - - $session = $query->getSingleResult(); - $session->resume(); - } catch (\Exception $e) { - $session = new Session; - $session->setUser($user); - $session->start(); - PartKeepr::getEM()->persist($session); - } - } else { - $session = new Session(); - $session->setUser(null); - $session->start(); - PartKeepr::getEM()->persist($session); - } - - PartKeepr::getEM()->flush(); - - self::$currentSession = $session; - - return $session; - } - - public function resumeSession ($session) { - $query = PartKeepr::getEM()->createQuery("SELECT s FROM PartKeepr\\Session\\Session s WHERE s.sessionid = :session"); - $query->setParameter("session", $session); - $query->execute(); - try { - self::$currentSession = $query->getSingleResult(); - return self::$currentSession; - } catch (\Doctrine\ORM\NonUniqueResultException $e) { - throw new \Exception("Fatal error: Multiple sessions with id $session found."); - } catch (\Doctrine\ORM\NoResultException $e) { - throw new SessionNotFoundException($session); - } - - } -} -?>- \ No newline at end of file