/** * Get all * * @access public * @return array $packages */ public static function get_all() { $skeletons = parent::get_all(); $packages = []; foreach ($skeletons as $skeleton) { if (strpos($skeleton->name, 'skeleton') !== 0) { continue; } $packages[] = $skeleton; } return $packages; }
/** * Delete skeleton * * @param int $id Skeleton ID * @return array * * @url DELETE skeleton/{id} */ function delete($id) { if (!DolibarrApiAccess::$user->rights->skeleton->supprimer) { throw new RestException(401); } $result = $this->skeleton->fetch($id); if (!$result) { throw new RestException(404, 'Skeleton not found'); } if (!DolibarrApi::_checkAccessToResource('skeleton', $this->skeleton->id)) { throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } if (!$this->skeleton->delete($id)) { throw new RestException(500); } return array('success' => array('code' => 200, 'message' => 'Skeleton deleted')); }
/** * Build a fake class dynamically that extends the desired class, * but will act more like a Friend class on a dynamically created mock. * This lets you use the mock methods in order to validate inputs and * return good, simulated values. * * By using the class renaming functionality of Renamer, the mock is * generated whenever you use the "new" keyword on the class we're * changing. Please consider restructuring your code to use some sort * of dependency injection since overriding "new" is an icky hack. * * Arguments for the callback, when used, should be like this: * function ($testObject, $newMockObject, $constructorArguments) * * @param string $type Name of class to mock * @param callback $callback Constructor callback for mock set up * @param array $methodsToKeep array to pass to getMockExceptMethods * @param boolean $callParent should the mock call the parent constructor */ public function stubWithMock($mocker, $className, $methodsToKeep = array(), $callParent = false) { $methodsToKeep = (array) $methodsToKeep; // Build unique information about this mock for building a key $mockInfo = array(); $mockInfo['class'] = strtolower($className); $methodsToKeep = array_map('strtolower', $methodsToKeep); sort($methodsToKeep); $mockInfo['methodsToKeep'] = $methodsToKeep; $mockInfo['callParent'] = $callParent; // Generate a key so we don't make the same sort of mock twice, then // check that key to see if we need to build the object $mockKey = serialize($mockInfo); if (!isset(self::$stubWithMockCache[$mockKey])) { // First, we will need to generate or reuse a mock object as our base class $mockObject = $mocker(); $skeleton = new Skeleton($mockObject); $php = 'PHPToolsTestUtil::stubWithMockConstructor("' . addslashes($mockKey) . '", $this, func_get_args());'; if ($callParent) { $reflection = $skeleton->reflect()->getConstructor(); $php .= $skeleton->chainMethod($reflection); } $skeleton->setConstructor($php); $skeletonClass = $skeleton->create(); self::$stubWithMockCache[$mockKey] = (object) array('className' => $skeletonClass, 'key' => $mockKey); } $mockDef = self::$stubWithMockCache[$mockKey]; $mockDef->callback = null; self::getRenamer()->renameClass($className, $mockDef->className); return $mockDef; }
<?php // PHPGen default index page // Include the PGPGen page generator include './static/skeleton.php'; $skeleton = new Skeleton(); // Set the page name $skeleton->setPageName("PHPGen Test Page"); // Start output buffer collection for the CSS ob_start(); ?> <link rel="stylesheet" type="text/css" href="/css/style.css"> <?php // Get the output buffer contents and then set the CSS to it $cnt = ob_get_clean(); $skeleton->setCSS($cnt); // Start output buffer collection for the main content ob_start(); ?> <h2> PHPGen </h2> <p> This is a test page for PHPGen. </p> <?php $cnt = ob_get_clean(); $skeleton->setMainCnt($cnt); // Start output buffer collection for the JavaScript ob_start();
/** * Create Skeleton * * @param array $authentication Array of authentication information * @param Skeleton $skeleton $skeleton * @return array Array result */ function createSkeleton($authentication, $skeleton) { global $db, $conf, $langs; $now = dol_now(); dol_syslog("Function: createSkeleton login=" . $authentication['login']); if ($authentication['entity']) { $conf->entity = $authentication['entity']; } // Init and check authentication $objectresp = array(); $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters if (!$error) { $newobject = new Skeleton($db); $newobject->prop1 = $skeleton->prop1; $newobject->prop2 = $skeleton->prop2; //... $db->begin(); $result = $newobject->create($fuser); if ($result <= 0) { $error++; } if (!$error) { $db->commit(); $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref); } else { $db->rollback(); $error++; $errorcode = 'KO'; $errorlabel = $newobject->error; } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }
/** * Gets a static class name for a method to work around a PHP bug with * reflection and late static binding calling down to descendents. * * @return string */ protected function getStaticClassName() { $originalName = get_class($this->object); if (!empty(static::$staticClassNames[$originalName])) { return static::$staticClassNames[$originalName]; } $skeleton = new Skeleton($originalName); $newClassName = $skeleton->create(); // Returns new class name static::$staticClassNames[$originalName] = $newClassName; return $newClassName; }
/** * Get produt or service * * @param array $authentication Array of authentication information * @param int $id Id of object * @param string $ref Ref of object * @param ref_ext $ref_ext Ref external of object * @return mixed */ function getSkeleton($authentication, $id, $ref = '', $ref_ext = '') { global $db, $conf, $langs; dol_syslog("Function: getSkeleton login="******" id=" . $id . " ref=" . $ref . " ref_ext=" . $ref_ext); if ($authentication['entity']) { $conf->entity = $authentication['entity']; } // Init and check authentication $objectresp = array(); $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters if (!$error && ($id && $ref || $id && $ref_ext || $ref && $ref_ext)) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; } if (!$error) { $fuser->getrights(); if ($fuser->rights->skeleton->read) { $skeleton = new Skeleton($db); $result = $skeleton->fetch($id, $ref, $ref_ext); if ($result > 0) { // Create $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'skeleton' => array('prop1' => $skeleton->prop1, 'prop2' => $skeleton->prop2)); } else { $error++; $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id=' . $id . ' nor ref=' . $ref . ' nor ref_ext=' . $ref_ext; } } else { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }