/** * This method will add the data pulled in by our join to an array representation of a model. * * @param PropelSOAModel $model * @param array $data */ public function addJoinedDataToResultArray(PropelSOAModel $model, array &$data) { $classInfo = Factory::createNewObject(SymfonyClassInfo::class); $classInfo->parseClassPath(get_class($model)); $peerClass = $classInfo->getClassPath('peer'); $peer = Factory::createNewObject($peerClass); $getMethod = $peer->linkedData[$this->relation]; $data[$this->relation] = $model->{$getMethod}(); }
/** * This method will download one script file and save it to the proper destination. * * @param InputInterface $input * @param OutputInterface $output * @param $controllerFilePath * @param $baseUrl */ protected function generateScript(InputInterface $input, OutputInterface $output, $controllerFilePath, $baseUrl) { $pieces = explode('/', $controllerFilePath); $srcIndex = array_search('src', $pieces); if ($srcIndex === false) { throw new Exception('Could not find the src directory'); } $params = []; $params['namespace'] = $pieces[$srcIndex + 1]; $params['bundle'] = str_replace('Bundle', '', $pieces[$srcIndex + 2]); $lastIndex = count($pieces) - 1; $className = str_replace('.php', '', $pieces[$lastIndex]); $params['entity'] = str_replace('Controller', '', $className); // check to see if this controller is really a service resource $classInfo = $this->classInfo = Factory::createNewObject(SymfonyClassInfo::class); $classInfo->namespace = $params['namespace']; $classInfo->bundle = $params['bundle']; $classInfo->entity = $params['entity']; $routesToGenerate = []; $controllerClass = $classInfo->getClassPath('controller'); $reflectionObject = Factory::createNewObject(ReflectionClass::class, [$controllerClass]); // if the controller is abstract, skip this entirely, don't implement any functionality for // the controller in JavaScript if ($reflectionObject->isAbstract()) { return; } // based on reflection, we will determine which types of objects should get standard class // definitions in the javascript. note that objects that do not get standard definitions // can get custom object definitions where the developer can make the javascript do similar // tasks but in a non-standard way. if ($reflectionObject->isSubclassOf(ModelBasedServiceController::class)) { // model-based controllers get query and object definitions generated. this is because // we can predict the data they should contain by inspecting the model, and we know // generally how to query for this data in a standard way through Propel $routesToGenerate['query'] = 'propelsoa_generatequery_route'; $routesToGenerate['object'] = 'propelsoa_generateobject_route'; } if ($reflectionObject->implementsInterface(Collectionable::class)) { // a controller signals that it wants us to build a standard collection object for it // by implementing the Collectionable interface $routesToGenerate['collection'] = 'propelsoa_generatecollection_route'; } // for a lot of objects, the basic generated object is not enough in javascript. we want our // javascript objects to be strong and contain all of their related logic and data. what // this means is that the generated object is a good starting point, but not the final // result. we can indicate with an interface that we want the generated object to not be // the final object loaded by getNewObject() in propelsoa. if ($reflectionObject->implementsInterface(ClientExtendable::class)) { $routesToGenerate['object'] = 'propelsoa_generatepartialobject_route'; } $router = $this->getContainer()->get('router'); foreach ($routesToGenerate as $routeKey) { $url = $baseUrl . $router->generate($routeKey, $params); $this->code .= $this->commandUtility->fileGetContents($url); } }
/** * This action will send an email to the correct Builder Professional team. * * @param Request $request */ public function postAction(Request $request) { $rawData = $request->getContent(); $post = json_decode($rawData, true); $contactUsValidator = Factory::createNewObject(Validator::class); if (!$contactUsValidator->validateWithRulesKey($post, 'contactus')) { return $contactUsValidator->getHttpErrorResponse(); } $contactUsData = [$post['Name'], $post['Email'], $post['Phone'], $post['Time'], $post['Question']]; $contactUsNotification = Factory::createNewObject(ContactUs::class, $contactUsData); $contactUsNotification->send(); return new PropelSOASuccessResponse(['sent' => true]); }
/** * This method will determine if the current client or user has access to view our materials. * * @return int */ public function isAuthorized() { $clientPeer = Factory::createNewObject(ClientPeer::class); $clientId = $clientPeer->getWorkingClientId(); if ($clientId === null) { return true; } $client = Factory::createNewQueryObject(ClientQuery::class)->findOneByClientId($clientId); foreach ($client->getClientProducts() as $clientProduct) { if ($clientProduct->getProductId() == $this->getBillingProductId()) { // Our related product is in the list of products the client has access to, so they should be able to view this. return 1; } if ($clientProduct->getProduct()->getCode() == 'NEVER_STOP_LEARNING') { // This client is on the all-access plan, and should always have access return 1; } } return 0; }
/** * This method will execute the main trunk of execution for this command including * finding model system files throughout the application. * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $this->commandUtility = Factory::createNewObject(CommandUtility::class); $this->determineBaseClasses(); // find all model directories in the project $directoryList = []; $listDirectoryCommand = 'find ./src -type d |grep -v "SOA/SOABundle" |grep "Model/om$"'; $this->commandUtility->exec($listDirectoryCommand, $directoryList); $listPeerCommand = 'find %s -maxdepth 1 -type f |grep "Peer.php$"'; $listQueryCommand = 'find %s -maxdepth 1 -type f |grep "Query.php$"'; $listModelCommand = 'find %s -maxdepth 1 -type f |grep -v "Query.php$" |grep -v "Peer.php$"'; // this is how many duplicated slashes it takes to get through all of the condensation, why can't // namespace paths be with pipes or something instead?? $separator = '\\\\\\\\'; foreach ($directoryList as $directory) { $this->replaceInFiles(sprintf($listPeerCommand, $directory), 'abstract class \\(.*\\)Peer', '& extends ' . $separator . implode($separator, $this->peerBaseParts)); $this->replaceInFiles(sprintf($listQueryCommand, $directory), 'extends ModelCriteria', 'extends ' . $separator . implode($separator, $this->queryBaseParts)); $this->replaceInFiles(sprintf($listModelCommand, $directory), 'extends BaseObject', 'extends ' . $separator . implode($separator, $this->modelBaseParts)); } }
public function testCreateNewObjectProperlySuppliesConstructorParametersWhenNotMocked() { $propertyValue = 'Hello World!'; $helperObject = Factory::createNewObject(HelperObject::class, [$propertyValue]); $this->assertEquals($propertyValue, $helperObject->property); }
/** * This method will make sure the actual question text will get sent to Mongo for us to remember. * * @param Request $request * @param Question $question */ protected function afterSave(Question $question) { $request = $this->getRequest(); $post = json_decode($request->getContent()); $question->setQuestion($post->QuestionText); $question->save(); // Let the support team know that a customer has a question $newQuestionNotification = Factory::createNewObject(NewQuestion::class, [$question]); $newQuestionNotification->send(); return $question; }
/** * This method will send the notification out to allow someone to convert from a signup to a * billing client for the training system. * * @param Signup $signup */ protected function notify(Signup $signup) { $signupNotification = Factory::createNewObject(SignupConfirmation::class, [$signup]); $signupNotification->send(); }
/** * This constructor will set up the answer as a document property to be stored in Mongo. */ public function __construct() { $answerDocumentProperty = Factory::createNewObject(DocumentProperty::class, ['answer', 'getAnswer', 'setAnswer', $this]); $this->documentProperties = [$answerDocumentProperty]; }
/** * This constructor will set us up to store our question text in MongoDB. */ public function __construct() { $questionDocumentProperty = Factory::createNewObject(DocumentProperty::class, ['question', 'getQuestion', 'setQuestion', $this]); $this->documentProperties = [$questionDocumentProperty]; }
/** * This method will get our relation key pluralized. * * @return string */ protected function getPluralRelationName() { if (isset($this->pluralRelationName)) { return $this->pluralRelationName; } $pluralizer = Factory::createNewObject(StandardEnglishPluralizer::class); $this->pluralRelationName = $pluralizer->getPluralForm($this->relation); return $this->pluralRelationName; }