Get a clone with special logic
Any copy will be changed to staged

@param string $createdByUserId
@param string $createdReason

@return ContainerInterface|ContainerAbstract
481728
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var ContainerInterface|ContainerAbstract $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        $new->lastPublished = new \DateTime();

        $new->revisions = new ArrayCollection();

        if (!empty($new->publishedRevision)) {
            $revision = $new->publishedRevision->newInstance(
                $createdByUserId,
                $createdReason
            );
            $new->removePublishedRevision();
            $new->revisions->add($revision);
            $new->setStagedRevision($revision);
        } elseif (!empty($new->stagedRevision)) {
            $revision = $new->stagedRevision->newInstance(
                $createdByUserId,
                $createdReason
            );
            $new->setStagedRevision($revision);
            $new->revisions->add($revision);
        }

        return $new;
    }
654922
public function getDefaultSiteValues(
        array $defaultSiteSettings,
        string $createdByUserId,
        string $createdReason
    ) {
        // Site Id
        if (empty($defaultSiteSettings['siteId'])) {
            $defaultSiteSettings['siteId'] = null;
        }

        // Language
        if (empty($defaultSiteSettings['languageIso6392t'])) {
            $defaultSiteSettings['languageIso6392t'] = $this->defaultLanguageIso6392t;
        }

        // Country
        if (empty($defaultSiteSettings['countryId'])) {
            $defaultSiteSettings['countryId'] = $this->defaultCountryIso3;
        }

        return $this->prepareSiteData(
            $defaultSiteSettings,
            $createdByUserId,
            $createdReason
        );
    }
614570
protected function createUser( UserResponseInterface $response )
    {
        $user = $this->userManager->createUser();
        $user->setUsername( $this->createUniqueUsername( $this->getRealName( $response )));
        $user->setEmail( $this->getEmail( $response ) );
        $user->setPassword( '' );
        $user->setEnabled( true );
        $this->userManager->updateUser( $user );
        $this->createIdentity( $user, $response );
        return $user;
    }
492561
public function add($userId, array $data=null, $getOrCreate=null)
    {
        $endpoint = 'user/';
        $payload = [
            'id' => $userId,
        ];
        if( $data !== null ){
            $payload['data'] = $data;
        }
        if($getOrCreate){
            $endpoint .= '?get_or_create=true';
        }
        $response = $this->doRequest('POST', $endpoint, $payload);
        $body = $response->getBody()->getContents();
        return json_decode($body, true);
    }
599089
public function quarterback2fa($createUserCommand) {

        // Get inputs into array
        $data = (array) $createUserCommand;


        // Sanitize
        $data = $this->sanitize($data, "create");

        // Wash the phone number
        $data['phone_number'] = $this->repository->washPhoneNumber($data['phone_number']);


        // Validate
        if ($this->validate($data, "create") != "passed") {
            // Prepare the response array, and then return to the edit form with error messages
            return $this->prepareResponseArray('validation_failed', 500, $data, $this->validate($data, "create"));
        }

        // Extra user validation
        $extraUserValidation = $this->extraUserValidation->extraValidation($data);
        if ($extraUserValidation['status_text'] != "extra_validation_successful") {
            // Prepare the response array, and then return to the edit form with error messages
            return $this->prepareResponseArray('validation_failed', 500, $data, $extraUserValidation['errorMessages']);
        }


        // We're here just to validate the data, not to create a database record.
        // So, no persist!

        // Prepare the response array, and then return to the command
        return $this->prepareResponseArray('validation_successful', 200, $data);
    }
217622
static function create( $contentObjectID, $userIdentifier, $creatorID = false )
    {
        $timestamp = time();

        if ( $creatorID === false )
        {
            $user = eZUser::currentUser();
            $creatorID = $user->id();
        }
        $row = array( 'contentobject_id' => $contentObjectID,
                      'user_identifier' => $userIdentifier,
                      'creator_id' => $creatorID,
                      'created' => $timestamp,
                      'modified' => $timestamp );
        return new eZInformationCollection( $row );
    }
89377
public function createContainer(
        SiteEntity $site,
        string $name,
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON,
        $author = Tracking::UNKNOWN_AUTHOR
    ) {
        $container = new ContainerEntity(
            $createdByUserId,
            $createdReason
        );
        $container->setName($name);
        $container->setSite($site);
        $container->setAuthor($author);

        $this->_em->persist($container);
        $this->_em->flush($container);

        return $container;
    }
152544
public function store(CreateUserRequest $request)
    {
        $user = User::create([
            'name' => $request->input('name'),
            'email' => $request->input('email'),
            'password' => bcrypt($request->input('password')),
        ]);

        event(new UserCreated($user));

        return $user;
    }
255106
public function create(UserInterface $user)
    {
        $entity = static::ENTITY_CLASSNAME;

        $reminder = new $entity($user);

        $this->save($reminder);

        return $reminder;
    }
184337
public function createRequest($requestId, $url, UserEvent $event, EventQueue $queue)
    {
        $start = microtime(true);
        return new Request([
            'url' => $url,
            'responseCallback' => function ($headers, $code) use ($requestId, $start) {
                $end = microtime(true);
                $this->logDebug('[' . $requestId . ']Reponse (after ' . ($end - $start) . 's): ' . $code);
            },
            'resolveCallback' =>
                function (Response $response) use ($requestId, $url, $event, $queue, $start) {
                    $data = $response->getBody()->getContents();
                    $headers = $response->getHeaders();
                    array_walk($headers, function (&$value, $key) use ($response) {
                        $value = $response->getHeader($key);
                    });
                    $code = $response->getStatusCode();
                    $end = microtime(true);
                    $message = '[';
                    $message .= $requestId;
                    $message .= ']Download complete (after ';
                    $message .= ($end - $start);
                    $message .= 's): ';
                    $message .= strlen($data);
                    $message .= ' in length length';
                    $this->logDebug($message);
                    $this->emitShorteningEvents($requestId, $url)->then(
                        function ($shortUrl) use ($url, $data, $headers, $code, $end, $start, $event, $queue) {
                            $this->sendMessage(
                                new Url($url, $data, $headers, $code, $end - $start, $shortUrl),
                                $event,
                                $queue
                            );
                        },
                        function () use ($url, $data, $headers, $code, $end, $start, $event, $queue) {
                            $this->sendMessage(new Url($url, $data, $headers, $code, $end - $start), $event, $queue);
                        }
                    );
                },
        ]);
    }
10785
public function createPage(
        SiteEntity $site,
        $pageData,
        $publishPage = false,
        $doFlush = true
    ) {
        if (empty($pageData['createdByUserId'])) {
            throw new PageException('CreatedByUserId is required to create a page.');
        }
        if (empty($pageData['createdReason'])) {
            $pageData['createdReason'] = Tracking::UNKNOWN_REASON;
        }
        if (empty($pageData['author'])) {
            throw new PageException('Author is required to create a page.');
        }
        $revision = new Revision(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $revision->setAuthor($pageData['author']);

        // we should not have an Id on page create
        unset($pageData['pageId']);

        $page = new PageEntity(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $page->populate($pageData);

        $page->setSite($site);

        $this->assertCanCreateSitePage(
            $page->getSite(),
            $page->getName(),
            $page->getPageType()
        );

        if (!$publishPage) {
            $page->setStagedRevision($revision);
        } else {
            $page->setPublishedRevision($revision);
        }

        $page->addRevision($revision);

        $this->_em->persist($revision);
        $this->_em->persist($page);

        if ($doFlush) {
            $this->_em->flush(
                [
                    $revision,
                    $page
                ]
            );
        }

        return $page;
    }
1005890
public function newInstance($selfedit = "false", $instanceName=null, $instanceClass=null) {
        //$componentsList = Moufspector::getComponentsList();
        $this->selfedit = $selfedit;
        $componentsList = MoufReflectionProxy::getComponentsList($selfedit=="true");
        sort($componentsList);

        $template = $this->template;
        $template->addContentFunction(array($this, "displayNewInstanceScreen"), $componentsList, $selfedit, $instanceName, $instanceClass);
        //$template->addContentFile(dirname(__FILE__)."/../views/displayNewInstance.php", $this);
        $template->toHtml();
    }
1280835
public static function create($quizid, $userid = null) {
        global $DB;

        $quiz = quiz_access_manager::load_quiz_and_settings($quizid);
        $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
        $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST);

        // Update quiz with override information.
        if ($userid) {
            $quiz = quiz_update_effective_access($quiz, $userid);
        }

        return new quiz($quiz, $cm, $course);
    }
483026
public function create($siteId, $userAgent = '', $requestIPAddress = '')
    {
        if (empty($siteId)) {
            throw new \Exception('Cannot create an instance without a site id');
        }

        $cookie = new Cookie();

        $userId = $cookie->getCookie(CookieNames::USER_ID);
        $userId = ! empty($userId) ? $userId : Uuid::v4();

        $payload = new Payload(new Cookie(), $siteId, $userId);

        $requestHeaders = [];

        $browserUserAgent = !empty($userAgent) ? $userAgent : Browser::getUserAgent();
        $browserIPAddress = !empty($requestIPAddress) ? $requestIPAddress : Browser::getRequestIPAddress();

        if (! empty($browserUserAgent)) {
            $requestHeaders['X-Original-User-Agent'] = $browserUserAgent;
        }

        if (! empty($browserIPAddress)) {
            $requestHeaders['X-Original-Request-IP-Address'] = $browserIPAddress;
        }

        $client = new Client([
            'base_uri' => API::ENDPOINT,
            RequestOptions::HEADERS => $requestHeaders,
            RequestOptions::HTTP_ERRORS => false,
            RequestOptions::VERIFY => false
        ]);

        return new Tracker($cookie, $payload, $client);
    }
137201
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
    {
        // The provider does nothing, but is required
        $providerId = sprintf('%s.%s', self::PROVIDER_SWITCH_USER_STATELESS, $id);
        $container->setDefinition(
            $providerId,
            new DefinitionDecorator(self::PROVIDER_SWITCH_USER_STATELESS)
        );

        // The listener does the logic
        $listenerId = sprintf('%s.%s', self::LISTENER_SWITCH_USER_STATELESS, $id);
        $container
            ->setDefinition(
                $listenerId,
                new DefinitionDecorator(self::LISTENER_SWITCH_USER_STATELESS)
            )
            ->replaceArgument(1, new Reference($userProvider))
            ->replaceArgument(3, $id)
            ->replaceArgument(6, $config['parameter'])
            ->replaceArgument(7, $config['role'])
        ;

        return [$providerId, $listenerId, $defaultEntryPoint];
    }
34159
public function newInstanceIfHasRevision(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        $new = parent::newInstanceIfHasRevision(
            $createdByUserId,
            $createdReason
        );

        if (empty($new)) {
            return null;
        }

        $new->pageId = null;
        $new->parent = null;

        return $new;
    }
427401
public function getDefaultSitePageSettings(
        array $defaultSiteSettings,
        string $author,
        string $createdByUserId,
        string $createdReason
    ) {
        $pagesData = (array_key_exists('pages', $defaultSiteSettings) ? $defaultSiteSettings['pages'] : []);

        // Set the author for each
        foreach ($pagesData as $key => $pageData) {
            $pagesData[$key]['createdByUserId'] = $createdByUserId;
            $pagesData[$key]['createdReason']
                = 'Default page creation in ' . get_class($this) . ' for: ' . $createdReason;
            $pagesData[$key]['author'] = $author;
        }

        return $pagesData;
    }