라라벨에서 사용하고 있는 Faker가 https://github.com/fzaninotto/Faker

 

입니다..  찾아보니 한글이 지원되네요..  아래 문장을 바로 아래에 넣으시면 됩니다.

$factory->define(Category::class, function (Faker $faker) {
$faker = \Faker\Factory::create('ko_kr');

 

vendor/fzaninotto/faker/src/Faker/Provider/ko_KR 안에..

Address, Company, Internet, Person, PHoneNumber, Text 가 지원됩니다.

 

텍스트는 이광수의 유정 이네요..

 

user는

$faker->name

$faker->unique()->safeEmail 로 형성이 가능합니다.  

단 갯수가 많으니 Random으로 발생시켜도 중복되는 이메일이 나옵니다.  지우고 다시 하거나, unique를 빼고 사용하세요.

 

그리고 많이 사용될 만한 것들이

$faker->word, $faker->sentence, $faker->sentences, $faker->paragraph(1) 등은 한글이 지원이 안되네요.

 

그래서 만들어 봤습니다.

vendor/fzaninotto/faker/src/Faker/Provider/Lorem.php에서 처리하는데..

이 Lorem.php를 ko_KR로 카피를 하면 자동으로 오버라이트 되는 것 같습니다. (상단 변경 필요,  아래 코드 참조)

 

중간에 ucwords가 한글을 깨먹는 것 같아서 커멘트 처리하니.. 잘 동작합니다.

 

한글 워드는 https://github.com/stympy/faker  여기서 가져왔습니다.

 

문장은 Word의 조합이라서 말은 안되지만,  그래도 영어보다는 보기가 편하네요..

 

고수분들이 문장을 별도 변수로 만들어 주시면 좋을 것 같습니다.  명언 300개정도로...ㅎㅎ

 

 

[code]

<?php

namespace Faker\Provider\ko_KR;

class Lorem extends \Faker\Provider\Lorem
{
protected static $wordList = array(
'국가는', '법률이', '정하는', '바에', '의하여', '재외국민을', '보호할', '의무를', '진다.', '모든', '국민은', '신체의',
'자유를', '가진다.', '국가는', '전통문화의', '계승·발전과', '민족문화의', '창달에', '노력하여야', '한다.', '통신·방송의',
'시설기준과', '신문의', '기능을', '보장하기', '위하여', '필요한', '사항은', '법률로', '정한다.', '헌법에', '의하여',
'체결·공포된', '조약과', '일반적으로', '승인된', '국제법규는', '국내법과', '같은', '효력을', '가진다.', '다만,', '현행범인인',
'경우와', '장기', '3년', '이상의', '형에', '해당하는', '죄를', '범하고', '도피', '또는', '증거인멸의', '염려가', '있을',
'때에는', '사후에', '영장을', '청구할', '수', '있다.', '저작자·발명가·과학기술자와', '예술가의', '권리는', '법률로써',
'보호한다.', '형사피고인은', '유죄의', '판결이', '확정될', '때까지는', '무죄로', '추정된다.', '모든', '국민은', '행위시의',
'법률에', '의하여', '범죄를', '구성하지', '아니하는', '행위로', '소추되지', '아니하며,', '동일한', '범죄에', '대하여',
'거듭', '처벌받지', '아니한다.', '국가는', '평생교육을', '진흥하여야', '한다.', '모든', '국민은', '사생활의', '비밀과',
'자유를', '침해받지', '아니한다.', '의무교육은', '무상으로', '한다.', '저작자·발명가·과학기술자와', '예술가의', '권리는',
'법률로써', '보호한다.', '국가는', '모성의', '보호를', '위하여', '노력하여야', '한다.', '헌법에', '의하여', '체결·공포된',
'조약과', '일반적으로', '승인된', '국제법규는', '국내법과', '같은', '효력을', '가진다.'
);

/**
* @example 'Lorem'
* @return string
*/
public static function word()
{
return static::randomElement(static::$wordList);
}

/**
* Generate an array of random words
*
* @example array('Lorem', 'ipsum', 'dolor')
* @param integer $nb how many words to return
* @param bool $asText if true the sentences are returned as one string
* @return array|string
*/
public static function words($nb = 3, $asText = false)
{
$words = array();
for ($i=0; $i < $nb; $i++) {
$words []= static::word();
}

return $asText ? implode(' ', $words) : $words;
}

/**
* Generate a random sentence
*
* @example 'Lorem ipsum dolor sit amet.'
* @param integer $nbWords around how many words the sentence should contain
* @param boolean $variableNbWords set to false if you want exactly $nbWords returned,
* otherwise $nbWords may vary by +/-40% with a minimum of 1
* @return string
*/
public static function sentence($nbWords = 6, $variableNbWords = true)
{
if ($nbWords <= 0) {
return '';
}
if ($variableNbWords) {
$nbWords = self::randomizeNbElements($nbWords);
}

$words = static::words($nbWords);

// $words[0] = ucwords($words[0]);

return implode($words, ' ') . '.';
}

/**
* Generate an array of sentences
*
* @example array('Lorem ipsum dolor sit amet.', 'Consectetur adipisicing eli.')
* @param integer $nb how many sentences to return
* @param bool $asText if true the sentences are returned as one string
* @return array|string
*/
public static function sentences($nb = 3, $asText = false)
{
$sentences = array();
for ($i=0; $i < $nb; $i++) {
$sentences []= static::sentence();
}

return $asText ? implode(' ', $sentences) : $sentences;
}

/**
* Generate a single paragraph
*
* @example 'Sapiente sunt omnis. Ut pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet.'
* @param integer $nbSentences around how many sentences the paragraph should contain
* @param boolean $variableNbSentences set to false if you want exactly $nbSentences returned,
* otherwise $nbSentences may vary by +/-40% with a minimum of 1
* @return string
*/
public static function paragraph($nbSentences = 3, $variableNbSentences = true)
{
if ($nbSentences <= 0) {
return '';
}
if ($variableNbSentences) {
$nbSentences = self::randomizeNbElements($nbSentences);
}

return implode(static::sentences($nbSentences), ' ');
}

/**
* Generate an array of paragraphs
*
* @example array($paragraph1, $paragraph2, $paragraph3)
* @param integer $nb how many paragraphs to return
* @param bool $asText if true the paragraphs are returned as one string, separated by two newlines
* @return array|string
*/
public static function paragraphs($nb = 3, $asText = false)
{
$paragraphs = array();
for ($i=0; $i < $nb; $i++) {
$paragraphs []= static::paragraph();
}

return $asText ? implode("\n\n", $paragraphs) : $paragraphs;
}

/**
* Generate a text string.
* Depending on the $maxNbChars, returns a string made of words, sentences, or paragraphs.
*
* @example 'Sapiente sunt omnis. Ut pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet.'
*
* @param integer $maxNbChars Maximum number of characters the text should contain (minimum 5)
*
* @return string
*/
public static function text($maxNbChars = 200)
{
if ($maxNbChars < 5) {
throw new \InvalidArgumentException('text() can only generate text of at least 5 characters');
}

$type = ($maxNbChars < 25) ? 'word' : (($maxNbChars < 100) ? 'sentence' : 'paragraph');

$text = array();
while (empty($text)) {
$size = 0;

// until $maxNbChars is reached
while ($size < $maxNbChars) {
$word = ($size ? ' ' : '') . static::$type();
$text[] = $word;

$size += strlen($word);
}

array_pop($text);
}

if ($type === 'word') {
// capitalize first letter
$text[0] = ucwords($text[0]);

// end sentence with full stop
$text[count($text) - 1] .= '.';
}

return implode($text, '');
}

protected static function randomizeNbElements($nbElements)
{
return (int) ($nbElements * mt_rand(60, 140) / 100) + 1;
}
}

[/code]

 

추천 1 비추천 0

댓글 0개

등록된 댓글이 없습니다.

전체 57건 3페이지
번호 제목 글쓴이 날짜 조회 추천 비추천
37

카페24에서 설치 후 에러 문의입니다.

2
나무 11/23 6417 0 0
36

이것은 제목 입니다.

2
홍길동 11/17 11 0 0
35

http 500 오류가 나네요

4
임성균 11/10 8999 0 0
34

서버환경 이건데 라라벨 서버 환경 되는건가요??

2
임성균 11/08 6864 0 0
33

쉘 관련 질문

2
임성균 11/08 4760 0 0
32

메뉴얼 대로 따라했는데 HTTP 500 오류 뜨네요

3
임성균 11/08 6923 0 0
31

언제 쫌 될까요? ㅎㅎ

3
옴바 11/08 3845 0 0
30

쉘에 코멘트 작성시 command not found 라고 뜨네요

5
임성균 11/06 8624 0 0
29

쪽지기능 에러

5
드림러 11/03 5662 0 0
28

라온보드 설치 후, 에러

5
드림러 11/03 8120 0 0