fromArray() public method

public fromArray ( array $data )
$data array
示例#1
0
 /**
  * @Given /^the site has following bundles:$/
  */
 public function theSiteHasFollowingBundles(TableNode $table)
 {
     $entityManager = $this->getEntityManager();
     foreach ($table->getHash() as $row) {
         $user = $this->users[$row['username']];
         $bundle = new Entity\Bundle();
         $bundle->fromArray(array('name' => $row['name'], 'user' => $user, 'username' => $user->getName(), 'description' => $row['description'], 'lastCommitAt' => new \DateTime($row['lastCommitAt'])));
         $bundle->setScore($row['score']);
         $this->setPrivateProperty($bundle, "trend1", $row['trend1']);
         $entityManager->persist($bundle);
     }
     $entityManager->flush();
 }
示例#2
0
文件: data.php 项目: ruian/KnpBundles
 public function load($manager)
 {
     $users = array();
     $trilean = array(true, false, null);
     $i = 0;
     foreach ($this->names as $name => $fullName) {
         $i++;
         $user = new Entity\User();
         $user->fromArray(array('name' => $name, 'email' => strtolower(str_replace(' ', '.', $fullName)) . '@foomail.bar', 'fullName' => $fullName, 'company' => $i % 2 ? 'Company ' . $i : null, 'location' => $i % 2 ? 'Location ' . $i : null, 'blog' => $i % 2 ? 'blog' . $i . '.com' : null, 'score' => 0));
         $manager->persist($user);
         $users[] = $user;
     }
     foreach ($users as $i => $user) {
         $contributors = array();
         $contributors[] = isset($users[$i + 1]) ? $users[$i + 1] : $users[0];
         $contributors[] = isset($users[$i - 1]) ? $users[$i - 1] : $users[count($users) - 1];
         $contributor = array_pop($contributors);
         $bundle = new Entity\Bundle();
         $bundle->fromArray(array('name' => ucfirst($user->getName()) . 'FooBundle', 'username' => $user->getName(), 'user' => $user, 'description' => 'Description of my bundle', 'homepage' => $i % 2 ? 'Bundle' . $i . '.com' : null, 'readme' => str_repeat("README of the bundle number " . $i . "\n", 20), 'tags' => $i % 2 ? array('1.0', '1.1') : array(), 'usesTravisCi' => $i % 2 ? false : true, 'composerName' => $i % 2 ? null : 'knplabs/knp-menu-bundle', 'travisCiBuildStatus' => $i % 2 == 0 ? $trilean[$i % 3] : null, 'nbFollowers' => $i * 10, 'nbForks' => $i, 'lastCommitAt' => new \DateTime('-' . $i * 4 . ' day'), 'lastCommits' => array(array('author' => array('name' => $contributor->getFullName(), 'login' => $contributor->getName(), 'email' => $contributor->getEmail()), 'url' => 'http://github.com', 'committed_date' => '2010-05-16T09:58:32-09:00', 'authored_date' => '2010-05-16T09:58:32-09:00', 'message' => 'Fix something on this ' . 'Bundle'), array('author' => array('name' => $user->getFullName(), 'login' => $user->getName(), 'email' => $user->getEmail()), 'url' => 'http://github.com', 'committed_date' => '2010-05-16T09:58:32-07:00', 'authored_date' => '2010-05-16T09:58:32-07:00', 'message' => 'Commit something on this bundle')), 'isFork' => false, 'contributors' => array($contributor)));
         $manager->persist($bundle);
         // Add some scores for bundles
         $today = new \DateTime();
         // We add a various number of scores for a given bundle
         $daysBefore = crc32($bundle->getName() . '-days') % 50;
         $maxScore = crc32($bundle->getName()) % 50;
         $previousScore = $maxScore;
         while ($daysBefore-- > 0) {
             $date = clone $today;
             $date->sub(new \DateInterval('P' . $daysBefore . 'D'));
             $score = new Entity\Score();
             $score->setBundle($bundle);
             $score->setValue($previousScore + $daysBefore);
             $score->setDate($date);
             $manager->persist($score);
             $previousScore = $score->getValue();
         }
     }
     $manager->flush();
 }
示例#3
0
 /**
  * @Given /^the site has following bundles:$/
  */
 public function theSiteHasFollowingBundles(TableNode $table)
 {
     $entityManager = $this->getEntityManager();
     $this->bundles = array();
     foreach ($table->getHash() as $row) {
         if (isset($this->developers[$row['username']])) {
             $owner = $this->developers[$row['username']];
         } elseif (isset($this->organizations[$row['username']])) {
             $owner = $this->organizations[$row['username']];
         } else {
             continue;
         }
         $bundle = new Entity\Bundle();
         $bundle->fromArray(array('name' => $row['name'], 'owner' => $owner, 'ownerName' => $owner->getName(), 'description' => $row['description'], 'readme' => isset($row['readme']) ? $row['readme'] : '', 'state' => isset($row['state']) ? $row['state'] : Entity\Bundle::STATE_UNKNOWN));
         if (isset($row['license'])) {
             $bundle->setLicenseType($row['license']);
         }
         if (isset($row['createdAt'])) {
             $bundle->setCreatedAt(new \DateTime($row['createdAt']));
         }
         if (isset($row['lastCommitAt'])) {
             $bundle->setLastCommitAt(new \DateTime($row['lastCommitAt']));
         }
         $bundle->setScore($row['score']);
         $versionsHistory['dependencies']['dev-master'] = array('name' => 'friendsofsymfony/user-bundle', 'extra' => array('branch-alias' => array('dev-master' => '2.0.x-dev')), 'require' => array('php' => '>=5.3.2'), 'require-dev' => '', 'suggest' => '');
         $bundle->setVersionsHistory($versionsHistory);
         $this->setPrivateProperty($bundle, "trend1", $row['trend1']);
         if (isset($row['recommendedBy'])) {
             $ownerNames = explode(',', $row['recommendedBy']);
             foreach ($ownerNames as $ownerName) {
                 $owner = $this->developers[trim($ownerName)];
                 $bundle->addRecommender($owner);
                 $owner->addRecommendedBundle($bundle);
                 $entityManager->persist($owner);
             }
         }
         $entityManager->persist($bundle);
         $this->bundles[$bundle->getName()] = $bundle;
     }
     $entityManager->flush();
 }
示例#4
0
 protected function makeBundle($manager, Entity\Owner $owner, $i, $contributor = null)
 {
     $trilean = array(true, false, null);
     $bundle = new Entity\Bundle();
     $bundle->fromArray(array('name' => ucfirst($owner->getName()) . $i . 'FooBundle', 'description' => $this->descriptions[mt_rand(0, 4)], 'homepage' => $i % 2 ? 'Bundle' . $i . '.com' : null, 'readme' => str_replace('__BUNDLE__', "the bundle number: {$i}", $this->readme), 'usesTravisCi' => $i % 2 ? false : true, 'composerName' => $i % 2 ? null : 'knplabs/knp-menu-bundle', 'versionsHistory' => array('symfony' => array('dev-master' => '2.1.*', '1.2.0' => '2.0.*', '1.1.0' => '2.*'), 'dependencies' => array('dev-master' => array('name' => 'friendsofsymfony/user-bundle', 'extra' => array('branch-alias' => array('dev-master' => '2.0.x-dev')), 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => array('twig/twig' => '*', 'doctrine/doctrine-bundle' => '*', 'swiftmailer/swiftmailer' => '*', 'willdurand/propel-typehintable-behavior' => 'dev-master', 'symfony/validator' => '2.1.*', 'symfony/yaml' => '2.1.*'), 'suggest' => array('doctrine/couchdb-odm-bundle' => '*', 'doctrine/doctrine-bundle' => '*', 'doctrine/mongodb-odm-bundle' => '*')), '1.2.x-dev' => array('name' => 'friendsofsymfony/user-bundle', 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => '', 'suggest' => ''))), 'state' => $this->states[mt_rand(0, 3)], 'license' => $i % 4 == 0 ? 'Some pseudo license data' : null, 'licenseType' => $i % 3 == 0 ? $this->licenses[mt_rand(0, 2)] : null, 'travisCiBuildStatus' => $i % 2 == 0 ? $trilean[$i % 3] : null, 'nbFollowers' => $i * 10, 'nbForks' => $i, 'isFork' => false, 'contributors' => $contributor ? array($contributor) : array(), 'canonicalConfig' => $i % 2 == 0 ? $this->canonicalConfigDump : null, 'nbRecommenders' => rand(0, 90)));
     $commits = array(array('date' => '2010-05-16T09:58:32-09:00', 'author' => $owner instanceof Entity\Developer ? $owner->getName() : 'Random Person', 'message' => 'Fix something on this Bundle'), array('date' => '2010-05-16T09:58:32-07:00', 'author' => 'Fake Name', 'message' => 'Commit something on this bundle'));
     foreach ($commits as $commit) {
         $lastCommitAt = new \DateTime();
         $lastCommitAt->setTimestamp(strtotime($commit['date']));
         $bundle->setLastCommitAt($lastCommitAt);
         $activity = new Entity\Activity();
         $activity->setType(Entity\Activity::ACTIVITY_TYPE_COMMIT);
         $activity->setMessage(strtok($commit['message'], "\n\r"));
         $activity->setCreatedAt($lastCommitAt);
         $activity->setBundle($bundle);
         if ($owner->getName() == $commit['author']) {
             $owner->setLastCommitAt($lastCommitAt);
             $activity->setDeveloper($owner);
             $activity->setBundleOwnerName(strtolower($owner->getName()));
         } else {
             $activity->setAuthor($commit['author']);
             $activity->setBundleOwnerName(strtolower($commit['author']));
         }
         $manager->persist($activity);
     }
     $owner->addBundle($bundle);
     return $bundle;
 }