idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
51,600
|
protected function shared_secret ( $ hash ) { $ length = 20 ; if ( $ hash == 'sha256' ) { $ length = 256 ; } $ secret = '' ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ secret .= mt_rand ( 0 , 255 ) ; } return $ secret ; }
|
Generates a random shared secret .
|
51,601
|
protected function keygen ( $ length ) { $ key = '' ; for ( $ i = 1 ; $ i < $ length ; $ i ++ ) { $ key .= mt_rand ( 0 , 9 ) ; } $ key .= mt_rand ( 1 , 9 ) ; return $ key ; }
|
Generates a private key .
|
51,602
|
function xrds ( $ force = null ) { if ( $ force ) { echo $ this -> xrdsContent ( ) ; die ( ) ; } elseif ( $ force === false ) { header ( 'X-XRDS-Location: ' . $ this -> xrdsLocation ) ; return ; } if ( isset ( $ _GET [ 'xrds' ] ) || ( isset ( $ _SERVER [ 'HTTP_ACCEPT' ] ) && strpos ( $ _SERVER [ 'HTTP_ACCEPT' ] , 'application/xrds+xml' ) !== false ) ) { header ( 'Content-Type: application/xrds+xml' ) ; echo $ this -> xrdsContent ( ) ; die ( ) ; } header ( 'X-XRDS-Location: ' . $ this -> xrdsLocation ) ; }
|
Displays an XRDS document or redirects to it . By default it detects whether it should display or redirect automatically .
|
51,603
|
protected function xrdsContent ( ) { $ lines = array ( '<?xml version="1.0" encoding="UTF-8"?>' , '<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">' , '<XRD>' , ' <Service>' , ' <Type>' . $ this -> ns . '/' . ( $ this -> select_id ? 'server' : 'signon' ) . '</Type>' , ' <URI>' . $ this -> serverLocation . '</URI>' , ' </Service>' , '</XRD>' , '</xrds:XRDS>' ) ; return implode ( "\n" , $ lines ) ; }
|
Returns the content of the XRDS document
|
51,604
|
protected function verify ( ) { if ( empty ( $ this -> assoc ) ) { return false ; } if ( empty ( $ this -> assoc [ 'private' ] ) ) { return false ; } if ( $ this -> data [ 'openid_response_nonce' ] != $ this -> assoc [ 'nonce' ] ) { return false ; } $ sig = array ( ) ; $ signed = explode ( ',' , $ this -> data [ 'openid_signed' ] ) ; foreach ( $ signed as $ field ) { $ name = strtr ( $ field , '.' , '_' ) ; if ( ! isset ( $ this -> data [ 'openid_' . $ name ] ) ) { return false ; } $ sig [ $ field ] = $ this -> data [ 'openid_' . $ name ] ; } $ sig = $ this -> keyValueForm ( $ sig ) ; if ( $ this -> data [ 'openid_sig' ] != base64_encode ( hash_hmac ( $ this -> assoc [ 'hash' ] , $ sig , $ this -> assoc [ 'mac' ] , true ) ) ) { return false ; } $ this -> assoc [ 'nonce' ] = null ; if ( empty ( $ this -> assoc [ 'private' ] ) ) { $ this -> setAssoc ( $ this -> assoc [ 'handle' ] , $ this -> assoc ) ; } else { $ this -> delAssoc ( $ this -> assoc [ 'handle' ] ) ; } return true ; }
|
Aids an RP in assertion verification .
|
51,605
|
protected function associate ( ) { if ( empty ( $ _SERVER [ 'HTTPS' ] ) && $ this -> data [ 'openid_session_type' ] == 'no-encryption' ) { $ this -> directErrorResponse ( ) ; } if ( ! $ this -> dh && substr ( $ this -> data [ 'openid_session_type' ] , 0 , 2 ) == 'DH' ) { $ this -> redirect ( $ this -> response ( array ( 'openid.error' => 'DH not supported' , 'openid.error_code' => 'unsupported-type' , 'openid.session_type' => 'no-encryption' ) ) ) ; } $ this -> assoc = array ( ) ; $ this -> assoc [ 'hash' ] = $ this -> data [ 'openid_assoc_type' ] == 'HMAC-SHA256' ? 'sha256' : 'sha1' ; $ this -> assoc [ 'handle' ] = $ this -> assoc_handle ( ) ; if ( $ this -> data [ 'openid_session_type' ] == 'no-encryption' ) { $ this -> assoc [ 'mac' ] = base64_encode ( $ this -> shared_secret ( $ this -> assoc [ 'hash' ] ) ) ; } else { $ this -> dh ( ) ; } $ response = array ( 'ns' => $ this -> ns , 'assoc_handle' => $ this -> assoc [ 'handle' ] , 'assoc_type' => $ this -> data [ 'openid_assoc_type' ] , 'session_type' => $ this -> data [ 'openid_session_type' ] , 'expires_in' => $ this -> assoc_lifetime ) ; if ( isset ( $ this -> assoc [ 'dh_server_public' ] ) ) { $ response [ 'dh_server_public' ] = $ this -> assoc [ 'dh_server_public' ] ; $ response [ 'enc_mac_key' ] = $ this -> assoc [ 'mac' ] ; } else { $ response [ 'mac_key' ] = $ this -> assoc [ 'mac' ] ; } echo $ this -> keyValueForm ( $ response ) ; die ( ) ; }
|
Performs association with an RP .
|
51,606
|
protected function generateAssociation ( ) { $ this -> assoc = array ( ) ; $ this -> assoc [ 'hash' ] = 'sha1' ; $ this -> assoc [ 'mac' ] = $ this -> shared_secret ( 'sha1' ) ; $ this -> assoc [ 'handle' ] = $ this -> assoc_handle ( ) ; }
|
Creates a private association .
|
51,607
|
protected function dh ( ) { if ( empty ( $ this -> data [ 'openid_dh_modulus' ] ) ) { $ this -> data [ 'openid_dh_modulus' ] = $ this -> default_modulus ; } if ( empty ( $ this -> data [ 'openid_dh_gen' ] ) ) { $ this -> data [ 'openid_dh_gen' ] = $ this -> default_gen ; } if ( empty ( $ this -> data [ 'openid_dh_consumer_public' ] ) ) { $ this -> directErrorResponse ( ) ; } $ modulus = $ this -> b64dec ( $ this -> data [ 'openid_dh_modulus' ] ) ; $ gen = $ this -> b64dec ( $ this -> data [ 'openid_dh_gen' ] ) ; $ consumerKey = $ this -> b64dec ( $ this -> data [ 'openid_dh_consumer_public' ] ) ; $ privateKey = $ this -> keygen ( strlen ( $ modulus ) ) ; $ publicKey = $ this -> powmod ( $ gen , $ privateKey , $ modulus ) ; $ ss = $ this -> powmod ( $ consumerKey , $ privateKey , $ modulus ) ; $ mac = $ this -> x_or ( hash ( $ this -> assoc [ 'hash' ] , $ ss , true ) , $ this -> shared_secret ( $ this -> assoc [ 'hash' ] ) ) ; $ this -> assoc [ 'dh_server_public' ] = $ this -> decb64 ( $ publicKey ) ; $ this -> assoc [ 'mac' ] = base64_encode ( $ mac ) ; }
|
Encrypts the MAC key using DH key exchange .
|
51,608
|
protected function x_or ( $ a , $ b ) { $ length = strlen ( $ a ) ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ a [ $ i ] = $ a [ $ i ] ^ $ b [ $ i ] ; } return $ a ; }
|
XORs two strings .
|
51,609
|
protected function response ( $ params ) { $ params += array ( 'openid.ns' => $ this -> ns ) ; return $ this -> data [ 'openid_return_to' ] . ( strpos ( $ this -> data [ 'openid_return_to' ] , '?' ) ? '&' : '?' ) . http_build_query ( $ params , '' , '&' ) ; }
|
Prepares an indirect response url .
|
51,610
|
protected function errorResponse ( ) { if ( ! empty ( $ this -> data [ 'openid_return_to' ] ) ) { $ response = array ( 'openid.mode' => 'error' , 'openid.error' => 'Invalid request' ) ; $ this -> redirect ( $ this -> response ( $ response ) ) ; } else { header ( 'HTTP/1.1 400 Bad Request' ) ; $ response = array ( 'ns' => $ this -> ns , 'error' => 'Invalid request' ) ; echo $ this -> keyValueForm ( $ response ) ; } die ( ) ; }
|
Outputs a direct error .
|
51,611
|
protected function positiveResponse ( $ identity , $ attributes ) { if ( ! $ this -> assoc ) { $ this -> generateAssociation ( ) ; $ this -> assoc [ 'private' ] = true ; } if ( $ this -> data [ 'openid_identity' ] == $ this -> data [ 'openid_claimed_id' ] || $ this -> select_id ) { $ this -> data [ 'openid_claimed_id' ] = $ identity ; } $ this -> data [ 'openid_identity' ] = $ identity ; $ params = array ( 'op_endpoint' => $ this -> serverLocation , 'claimed_id' => $ this -> data [ 'openid_claimed_id' ] , 'identity' => $ this -> data [ 'openid_identity' ] , 'return_to' => $ this -> data [ 'openid_return_to' ] , 'realm' => $ this -> data [ 'openid_realm' ] , 'response_nonce' => gmdate ( "Y-m-d\TH:i:s\Z" ) , 'assoc_handle' => $ this -> assoc [ 'handle' ] , ) ; $ params += $ this -> responseAttributes ( $ attributes ) ; if ( isset ( $ this -> data [ 'openid_assoc_handle' ] ) && $ this -> data [ 'openid_assoc_handle' ] != $ this -> assoc [ 'handle' ] ) { $ params [ 'invalidate_handle' ] = $ this -> data [ 'openid_assoc_handle' ] ; } $ sig = hash_hmac ( $ this -> assoc [ 'hash' ] , $ this -> keyValueForm ( $ params ) , $ this -> assoc [ 'mac' ] , true ) ; $ req = array ( 'openid.mode' => 'id_res' , 'openid.signed' => implode ( ',' , array_keys ( $ params ) ) , 'openid.sig' => base64_encode ( $ sig ) , ) ; $ this -> assoc [ 'nonce' ] = $ params [ 'response_nonce' ] ; $ this -> setAssoc ( $ this -> assoc [ 'handle' ] , $ this -> assoc ) ; foreach ( $ params as $ name => $ value ) { $ req [ 'openid.' . $ name ] = $ value ; } $ this -> redirect ( $ this -> response ( $ req ) ) ; }
|
Sends an positive assertion .
|
51,612
|
protected function responseAttributes ( $ attributes ) { if ( ! $ attributes ) return array ( ) ; $ ns = 'http://axschema.org/' ; $ response = array ( ) ; if ( isset ( $ this -> data [ 'ax' ] ) ) { $ response [ 'ns.ax' ] = 'http://openid.net/srv/ax/1.0' ; foreach ( $ attributes as $ name => $ value ) { $ alias = strtr ( $ name , '/' , '_' ) ; $ response [ 'ax.type.' . $ alias ] = $ ns . $ name ; $ response [ 'ax.value.' . $ alias ] = $ value ; } return $ response ; } foreach ( $ attributes as $ name => $ value ) { if ( ! isset ( $ this -> ax_to_sreg [ $ name ] ) ) { continue ; } $ response [ 'sreg.' . $ this -> ax_to_sreg [ $ name ] ] = $ value ; } return $ response ; }
|
Prepares an array of attributes to send
|
51,613
|
protected function b64dec ( $ str ) { $ bytes = unpack ( 'C*' , base64_decode ( $ str ) ) ; $ n = 0 ; foreach ( $ bytes as $ byte ) { $ n = $ this -> add ( $ this -> mul ( $ n , 256 ) , $ byte ) ; } return $ n ; }
|
Converts base64 encoded number to it s decimal representation .
|
51,614
|
protected function decb64 ( $ num ) { $ bytes = array ( ) ; while ( $ num ) { array_unshift ( $ bytes , $ this -> mod ( $ num , 256 ) ) ; $ num = $ this -> div ( $ num , 256 ) ; } if ( $ bytes && $ bytes [ 0 ] > 127 ) { array_unshift ( $ bytes , 0 ) ; } array_unshift ( $ bytes , 'C*' ) ; return base64_encode ( call_user_func_array ( 'pack' , $ bytes ) ) ; }
|
Complements b64dec .
|
51,615
|
public function preFlush ( PreFlushEventArgs $ event ) { $ em = $ event -> getEntityManager ( ) ; $ uow = $ em -> getUnitOfWork ( ) ; foreach ( $ uow -> getIdentityMap ( ) as $ className ) { foreach ( $ className as $ object ) { $ this -> translator -> storeTranslationData ( $ object ) ; } } }
|
Before flushing the data we have to check if some translation data was stored for an object .
|
51,616
|
public function preRemove ( LifecycleEventArgs $ args ) { $ entity = $ args -> getEntity ( ) ; $ this -> translator -> deleteTranslationData ( $ entity ) ; }
|
If entity will be deleted we need to delete all its translation data as well
|
51,617
|
public function postLoad ( LifecycleEventArgs $ args ) { $ entity = $ args -> getEntity ( ) ; $ this -> translator -> translate ( $ entity , $ this -> localeResolver -> getLocale ( ) ) ; }
|
Load TranslationData into to entity if it s fetched from the database
|
51,618
|
public function loadData ( $ name ) { $ file = sprintf ( '%s/../Resources/fixtures/%s.yml' , __DIR__ , $ name ) ; if ( ! file_exists ( $ file ) ) { throw new \ Exception ( sprintf ( 'fixtures file "%s" not found for name "%s"' , $ file , $ name ) ) ; } $ data = Yaml :: parse ( $ file ) ; $ items = [ ] ; foreach ( $ data as $ args ) { $ item = $ this -> create ( $ args ) ; $ this -> manager -> persist ( $ item ) ; $ items [ ] = $ item ; } $ this -> manager -> flush ( ) ; }
|
Load the data from fixture file and insert it into the database
|
51,619
|
protected function createImage ( $ path ) { $ path = sprintf ( '%s/../Resources/images/%s' , __DIR__ , $ path ) ; $ file = $ this -> container -> get ( 'enhavo_media.factory.file' ) -> createFromPath ( $ path ) ; return $ this -> container -> get ( 'enhavo_media.media.media_manager' ) -> saveFile ( $ file ) ; }
|
Save file and return its model .
|
51,620
|
public function createDateTime ( $ value ) { $ date = null ; if ( is_string ( $ value ) ) { $ date = new \ DateTime ( $ value ) ; } if ( is_int ( $ value ) ) { $ date = new \ DateTime ( ) ; $ date -> setTimestamp ( $ value ) ; } return $ date ; }
|
Return DateTime object
|
51,621
|
public static function compressIp ( $ ip ) { if ( filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { return current ( unpack ( 'A4' , inet_pton ( $ ip ) ) ) ; } elseif ( filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ) { return current ( unpack ( 'A16' , inet_pton ( $ ip ) ) ) ; } return false ; }
|
Converts a printable IP into an unpacked binary string
|
51,622
|
public static function expandIp ( $ str ) { if ( strlen ( $ str ) == 16 OR strlen ( $ str ) == 4 ) { return inet_ntop ( pack ( "A" . strlen ( $ str ) , $ str ) ) ; } return false ; }
|
Converts an unpacked binary string into a printable IP
|
51,623
|
public function run ( int $ type = WEBHOOK ) { if ( $ type == WEBHOOK ) { $ this -> _is_webhook = true ; $ this -> init ( ) ; $ this -> processWebhookUpdate ( ) ; return ; } if ( $ type == DEBUG ) { $ this -> debug = true ; } $ this -> init ( ) ; $ this -> getUpdatesLocal ( ) ; }
|
\ brief Start the bot .
|
51,624
|
public function getBotID ( ) : int { if ( ! isset ( $ this -> _bot_id ) || $ this -> _bot_id == 0 ) { $ this -> _bot_id = ( $ this -> getMe ( ) ) [ 'id' ] ; } return $ this -> _bot_id ?? 0 ; }
|
\ brief Get bot ID using getMe method .
|
51,625
|
public function withChatId ( $ chat_id , $ method , ... $ param ) { $ last_chat = $ this -> chat_id ; $ this -> chat_id = $ chat_id ; $ value = $ this -> $ method ( ... $ param ) ; $ this -> chat_id = $ last_chat ; return $ value ; }
|
\ brief Call a single api method using another chat_id without changing the current one .
|
51,626
|
protected function getProperty ( $ resource , $ property ) { if ( $ property == '_self' ) { return $ resource ; } $ propertyPath = explode ( '.' , $ property ) ; if ( count ( $ propertyPath ) > 1 ) { $ property = array_shift ( $ propertyPath ) ; $ newResource = $ this -> getProperty ( $ resource , $ property ) ; if ( $ newResource !== null ) { $ propertyPath = implode ( '.' , $ propertyPath ) ; return $ this -> getProperty ( $ newResource , $ propertyPath ) ; } else { return null ; } } else { $ method = sprintf ( 'is%s' , ucfirst ( $ property ) ) ; if ( method_exists ( $ resource , $ method ) ) { return call_user_func ( array ( $ resource , $ method ) ) ; } $ method = sprintf ( 'get%s' , ucfirst ( $ property ) ) ; if ( method_exists ( $ resource , $ method ) ) { return call_user_func ( array ( $ resource , $ method ) ) ; } } throw new PropertyNotExistsException ( sprintf ( 'Trying to call "get%s" or "is%s" on class "%s", but method does not exists. Maybe you spelled it wrong or you didn\'t add the getter for property "%s"' , ucfirst ( $ property ) , ucfirst ( $ property ) , get_class ( $ resource ) , $ property ) ) ; }
|
Return the value the given property and object .
|
51,627
|
public function addTranslationData ( $ entity , $ propertyPath , $ data ) { $ metadata = $ this -> metadataCollection -> getMetadata ( $ entity ) ; $ property = $ metadata -> getProperty ( $ propertyPath ) ; $ strategy = $ this -> strategyResolver -> getStrategy ( $ property -> getStrategy ( ) ) ; $ strategy -> addTranslationData ( $ entity , $ property , $ data , $ metadata ) ; }
|
Add translation data but does not store it .
|
51,628
|
public function normalizeToTranslationData ( $ entity , $ propertyPath , $ formData ) { $ metadata = $ this -> metadataCollection -> getMetadata ( $ entity ) ; $ property = $ metadata -> getProperty ( $ propertyPath ) ; $ strategy = $ this -> strategyResolver -> getStrategy ( $ property -> getStrategy ( ) ) ; return $ strategy -> normalizeToTranslationData ( $ entity , $ property , $ formData , $ metadata ) ; }
|
Normalize the form data . The data that a form contains after submit is a mix of the model data and the translation data . This function will return only the translation data .
|
51,629
|
public function deleteTranslationData ( $ entity ) { $ metadata = $ this -> metadataCollection -> getMetadata ( $ entity ) ; if ( $ metadata === null ) { return null ; } $ strategies = $ this -> strategyResolver -> getStrategies ( ) ; foreach ( $ strategies as $ strategy ) { $ strategy -> deleteTranslationData ( $ entity , $ metadata ) ; } }
|
Prepare deleting all translation data . Because this function should be called inside a doctrine hook it contains no flush .
|
51,630
|
public function getTranslationData ( $ entity , Property $ property ) { $ metadata = $ this -> metadataCollection -> getMetadata ( $ entity ) ; if ( $ metadata === null ) { return null ; } $ metaProperty = $ metadata -> getProperty ( $ property -> getName ( ) ) ; if ( $ metaProperty === null ) { throw new TranslationException ( sprintf ( 'The property "%s" was used for translation, but no metadata was found. Maybe you forgot to define one for the entity "%s"' , $ property -> getName ( ) , get_class ( $ entity ) ) ) ; } $ strategy = $ this -> strategyResolver -> getStrategy ( $ metaProperty -> getStrategy ( ) ) ; return $ strategy -> getTranslationData ( $ entity , $ metaProperty , $ metadata ) ; }
|
Return the translation data that is already stored in the database
|
51,631
|
public function postFlush ( ) { $ strategies = $ this -> strategyResolver -> getStrategies ( ) ; foreach ( $ strategies as $ strategy ) { $ strategy -> postFlush ( ) ; } }
|
This function should be called after the flush was executed .
|
51,632
|
public function translate ( $ entity , $ locale ) { $ metadata = $ this -> metadataCollection -> getMetadata ( $ entity ) ; if ( $ metadata === null ) { return null ; } if ( $ locale === $ this -> defaultLocale ) { return ; } $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; if ( $ metadata !== null ) { foreach ( $ metadata -> getProperties ( ) as $ property ) { $ strategy = $ this -> strategyResolver -> getStrategy ( $ property -> getStrategy ( ) ) ; $ value = $ strategy -> getTranslation ( $ entity , $ property , $ locale , $ metadata ) ; $ accessor -> setValue ( $ entity , $ property -> getName ( ) , $ value ) ; } } }
|
Translate an entity . All stored translation data will be applied to this object . It should be called only inside the doctrine postLoad hook because it doesn t handle recursive connections .
|
51,633
|
public function getTranslation ( $ entity , $ property , $ locale ) { $ metadata = $ this -> metadataCollection -> getMetadata ( $ entity ) ; if ( $ metadata === null ) { return null ; } $ property = $ metadata -> getProperty ( $ property ) ; if ( $ property === null ) { return null ; } $ strategy = $ this -> strategyResolver -> getStrategy ( $ property -> getStrategy ( ) ) ; return $ strategy -> getTranslation ( $ entity , $ property , $ locale , $ metadata ) ; }
|
Translate a single property of an entity .
|
51,634
|
public function init ( ) { if ( ! isset ( $ this -> dom -> documentElement ) ) { return false ; } $ this -> success = true ; $ bodyElems = $ this -> dom -> getElementsByTagName ( 'body' ) ; if ( null === $ this -> bodyCache ) { $ this -> bodyCache = '' ; foreach ( $ bodyElems as $ bodyNode ) { $ this -> bodyCache .= trim ( $ bodyNode -> getInnerHTML ( ) ) ; } } if ( $ bodyElems -> length > 0 && null === $ this -> body ) { $ this -> body = $ bodyElems -> item ( 0 ) ; } $ this -> prepDocument ( ) ; $ overlay = $ this -> dom -> createElement ( 'div' ) ; $ innerDiv = $ this -> dom -> createElement ( 'div' ) ; $ articleTitle = $ this -> getArticleTitle ( ) ; $ articleContent = $ this -> grabArticle ( ) ; if ( ! $ articleContent ) { $ this -> success = false ; $ articleContent = $ this -> dom -> createElement ( 'div' ) ; $ articleContent -> setAttribute ( 'class' , 'readability-content' ) ; $ articleContent -> setInnerHtml ( '<p>Sorry, Readability was unable to parse this page for content.</p>' ) ; } $ overlay -> setAttribute ( 'class' , 'readOverlay' ) ; $ innerDiv -> setAttribute ( 'class' , 'readInner' ) ; $ innerDiv -> appendChild ( $ articleTitle ) ; $ innerDiv -> appendChild ( $ articleContent ) ; $ overlay -> appendChild ( $ innerDiv ) ; $ this -> body -> setInnerHtml ( '' ) ; $ this -> body -> appendChild ( $ overlay ) ; $ this -> body -> removeAttribute ( 'style' ) ; $ this -> postProcessContent ( $ articleContent ) ; $ this -> articleTitle = $ articleTitle ; $ this -> articleContent = $ articleContent ; return $ this -> success ; }
|
Runs readability .
|
51,635
|
public function postProcessContent ( \ DOMElement $ articleContent ) { if ( $ this -> convertLinksToFootnotes && ! preg_match ( '/\bwiki/' , $ this -> url ) ) { $ this -> addFootnotes ( $ articleContent ) ; } }
|
Run any post - process modifications to article content as necessary .
|
51,636
|
public function addFootnotes ( \ DOMElement $ articleContent ) { $ footnotesWrapper = $ this -> dom -> createElement ( 'footer' ) ; $ footnotesWrapper -> setAttribute ( 'class' , 'readability-footnotes' ) ; $ footnotesWrapper -> setInnerHtml ( '<h3>References</h3>' ) ; $ articleFootnotes = $ this -> dom -> createElement ( 'ol' ) ; $ articleFootnotes -> setAttribute ( 'class' , 'readability-footnotes-list' ) ; $ footnotesWrapper -> appendChild ( $ articleFootnotes ) ; $ articleLinks = $ articleContent -> getElementsByTagName ( 'a' ) ; $ linkCount = 0 ; for ( $ i = 0 ; $ i < $ articleLinks -> length ; ++ $ i ) { $ articleLink = $ articleLinks -> item ( $ i ) ; $ footnoteLink = $ articleLink -> cloneNode ( true ) ; $ refLink = $ this -> dom -> createElement ( 'a' ) ; $ footnote = $ this -> dom -> createElement ( 'li' ) ; $ linkDomain = @ parse_url ( $ footnoteLink -> getAttribute ( 'href' ) , PHP_URL_HOST ) ; if ( ! $ linkDomain && isset ( $ this -> url ) ) { $ linkDomain = @ parse_url ( $ this -> url , PHP_URL_HOST ) ; } $ linkText = $ this -> getInnerText ( $ articleLink ) ; if ( ( false !== strpos ( $ articleLink -> getAttribute ( 'class' ) , 'readability-DoNotFootnote' ) ) || preg_match ( $ this -> regexps [ 'skipFootnoteLink' ] , $ linkText ) ) { continue ; } ++ $ linkCount ; $ refLink -> setAttribute ( 'href' , '#readabilityFootnoteLink-' . $ linkCount ) ; $ refLink -> setInnerHtml ( '<small><sup>[' . $ linkCount . ']</sup></small>' ) ; $ refLink -> setAttribute ( 'class' , 'readability-DoNotFootnote' ) ; $ refLink -> setAttribute ( 'style' , 'color: inherit;' ) ; if ( $ articleLink -> parentNode -> lastChild -> isSameNode ( $ articleLink ) ) { $ articleLink -> parentNode -> appendChild ( $ refLink ) ; } else { $ articleLink -> parentNode -> insertBefore ( $ refLink , $ articleLink -> nextSibling ) ; } $ articleLink -> setAttribute ( 'style' , 'color: inherit; text-decoration: none;' ) ; $ articleLink -> setAttribute ( 'name' , 'readabilityLink-' . $ linkCount ) ; $ footnote -> setInnerHtml ( '<small><sup><a href="#readabilityLink-' . $ linkCount . '" title="Jump to Link in Article">^</a></sup></small> ' ) ; $ footnoteLink -> setInnerHtml ( ( '' !== $ footnoteLink -> getAttribute ( 'title' ) ? $ footnoteLink -> getAttribute ( 'title' ) : $ linkText ) ) ; $ footnoteLink -> setAttribute ( 'name' , 'readabilityFootnoteLink-' . $ linkCount ) ; $ footnote -> appendChild ( $ footnoteLink ) ; if ( $ linkDomain ) { $ footnote -> setInnerHtml ( $ footnote -> getInnerHTML ( ) . '<small> (' . $ linkDomain . ')</small>' ) ; } $ articleFootnotes -> appendChild ( $ footnote ) ; } if ( $ linkCount > 0 ) { $ articleContent -> appendChild ( $ footnotesWrapper ) ; } }
|
For easier reading convert this document to have footnotes at the bottom rather than inline links .
|
51,637
|
public function getInnerText ( $ e , $ normalizeSpaces = true , $ flattenLines = false ) { if ( null === $ e || ! isset ( $ e -> textContent ) || '' === $ e -> textContent ) { return '' ; } $ textContent = trim ( $ e -> textContent ) ; if ( $ flattenLines ) { $ textContent = mb_ereg_replace ( '(?:[\r\n](?:\s| )*)+' , '' , $ textContent ) ; } elseif ( $ normalizeSpaces ) { $ textContent = mb_ereg_replace ( '\s\s+' , ' ' , $ textContent ) ; } return $ textContent ; }
|
Get the inner text of a node . This also strips out any excess whitespace to be found .
|
51,638
|
public function getWeight ( \ DOMElement $ e ) { if ( ! $ this -> flagIsActive ( self :: FLAG_WEIGHT_ATTRIBUTES ) ) { return 0 ; } $ weight = 0 ; $ weight += $ this -> weightAttribute ( $ e , 'class' ) ; $ weight += $ this -> weightAttribute ( $ e , 'id' ) ; return $ weight ; }
|
Get an element relative weight .
|
51,639
|
public function killBreaks ( \ DOMElement $ node ) { $ html = $ node -> getInnerHTML ( ) ; $ html = preg_replace ( $ this -> regexps [ 'killBreaks' ] , '<br />' , $ html ) ; $ node -> setInnerHtml ( $ html ) ; }
|
Remove extraneous break tags from a node .
|
51,640
|
protected function getArticleTitle ( ) { try { $ curTitle = $ origTitle = $ this -> getInnerText ( $ this -> dom -> getElementsByTagName ( 'title' ) -> item ( 0 ) ) ; } catch ( \ Exception $ e ) { $ curTitle = '' ; $ origTitle = '' ; } if ( preg_match ( '/ [\|\-] /' , $ curTitle ) ) { $ curTitle = preg_replace ( '/(.*)[\|\-] .*/i' , '$1' , $ origTitle ) ; if ( \ count ( explode ( ' ' , $ curTitle ) ) < 3 ) { $ curTitle = preg_replace ( '/[^\|\-]*[\|\-](.*)/i' , '$1' , $ origTitle ) ; } } elseif ( false !== strpos ( $ curTitle , ': ' ) ) { $ curTitle = preg_replace ( '/.*:(.*)/i' , '$1' , $ origTitle ) ; if ( \ count ( explode ( ' ' , $ curTitle ) ) < 3 ) { $ curTitle = preg_replace ( '/[^:]*[:](.*)/i' , '$1' , $ origTitle ) ; } } elseif ( mb_strlen ( $ curTitle ) > 150 || mb_strlen ( $ curTitle ) < 15 ) { $ hOnes = $ this -> dom -> getElementsByTagName ( 'h1' ) ; if ( 1 === $ hOnes -> length ) { $ curTitle = $ this -> getInnerText ( $ hOnes -> item ( 0 ) ) ; } } $ curTitle = trim ( $ curTitle ) ; if ( \ count ( explode ( ' ' , $ curTitle ) ) <= 4 ) { $ curTitle = $ origTitle ; } $ articleTitle = $ this -> dom -> createElement ( 'h1' ) ; $ articleTitle -> setInnerHtml ( $ curTitle ) ; return $ articleTitle ; }
|
Get the article title as an H1 .
|
51,641
|
protected function prepDocument ( ) { if ( null === $ this -> body ) { $ this -> body = $ this -> dom -> createElement ( 'body' ) ; $ this -> dom -> documentElement -> appendChild ( $ this -> body ) ; } $ this -> body -> setAttribute ( 'class' , 'readabilityBody' ) ; $ styleTags = $ this -> dom -> getElementsByTagName ( 'style' ) ; for ( $ i = $ styleTags -> length - 1 ; $ i >= 0 ; -- $ i ) { $ styleTags -> item ( $ i ) -> parentNode -> removeChild ( $ styleTags -> item ( $ i ) ) ; } $ linkTags = $ this -> dom -> getElementsByTagName ( 'link' ) ; for ( $ i = $ linkTags -> length - 1 ; $ i >= 0 ; -- $ i ) { $ linkTags -> item ( $ i ) -> parentNode -> removeChild ( $ linkTags -> item ( $ i ) ) ; } }
|
Prepare the HTML document for readability to scrape it . This includes things like stripping javascript CSS and handling terrible markup .
|
51,642
|
protected function weightAttribute ( \ DOMElement $ element , $ attribute ) { if ( ! $ element -> hasAttribute ( $ attribute ) ) { return 0 ; } $ weight = 0 ; $ attributeValue = trim ( $ element -> getAttribute ( $ attribute ) ) ; if ( '' !== $ attributeValue ) { if ( preg_match ( $ this -> regexps [ 'negative' ] , $ attributeValue ) ) { $ weight -= 25 ; } if ( preg_match ( $ this -> regexps [ 'positive' ] , $ attributeValue ) ) { $ weight += 25 ; } if ( preg_match ( $ this -> regexps [ 'unlikelyCandidates' ] , $ attributeValue ) ) { $ weight -= 5 ; } if ( preg_match ( $ this -> regexps [ 'okMaybeItsACandidate' ] , $ attributeValue ) ) { $ weight += 5 ; } } return $ weight ; }
|
Get an element weight by attribute . Uses regular expressions to tell if this element looks good or bad .
|
51,643
|
protected function reinitBody ( ) { if ( ! isset ( $ this -> body -> childNodes ) ) { $ this -> body = $ this -> dom -> createElement ( 'body' ) ; $ this -> body -> setInnerHtml ( $ this -> bodyCache ) ; } }
|
Will recreate previously deleted body property .
|
51,644
|
public function getStatus ( int $ default_status = - 1 ) : int { $ chat_id = $ this -> bot -> chat_id ; $ redis = $ this -> bot -> getRedis ( ) ; if ( $ redis -> exists ( $ chat_id . ':status' ) ) { $ this -> status = $ redis -> get ( $ chat_id . ':status' ) ; return $ this -> status ; } $ redis -> set ( $ chat_id . ':status' , $ default_status ) ; $ this -> status = $ default_status ; return $ this -> status ; }
|
\ brief Get current user status from Redis and set it in status variable . \ details Throws an exception if the Redis connection is missing .
|
51,645
|
public function getBackSkipKeyboard ( bool $ json_serialized = true ) { $ inline_keyboard = [ 'inline_keyboard' => [ [ [ 'text' => $ this -> bot -> local -> getStr ( 'Back_Button' ) , 'callback_data' => 'back' ] , [ 'text' => $ this -> bot -> local -> getStr ( 'Skip_Button' ) , 'callback_data' => 'skip' ] ] ] ] ; if ( $ json_serialized ) { return json_encode ( $ inline_keyboard ) ; } else { return $ inline_keyboard ; } }
|
\ brief Get a Back and a Skip buttons inthe same row . \ details Back button has callback_data back and Skip button has callback_data skip .
|
51,646
|
public function offsetGet ( $ offset ) { $ method = Text :: camelCase ( "get $offset" ) ; if ( method_exists ( $ this , $ method ) ) { return $ this -> { $ method } ( ) ; } return isset ( $ this -> container [ $ offset ] ) ? $ this -> container [ $ offset ] : null ; }
|
\ brief Get the given offset .
|
51,647
|
public function oldDispatch ( ) { foreach ( BasicBot :: $ update_types as $ offset => $ class ) { if ( method_exists ( $ this , 'process' . $ class ) ) { $ this -> answerUpdate [ $ offset ] = function ( $ bot , $ entity ) use ( $ class ) { $ bot -> { "process$class" } ( $ entity ) ; } ; } } }
|
\ brief Set compatibilityu mode for old processes method . \ details If your bot uses processMessage or another deprecated function call this method to make the old version works .
|
51,648
|
public function setChatLog ( string $ chat_id , bool $ skip_check = false ) { if ( ! $ skip_check && $ this -> getChat ( $ chat_id ) !== false ) { $ this -> chat_log = $ chat_id ; } }
|
\ brief Set chat_id choosed for logging .
|
51,649
|
protected function generateAnnotations ( ) { $ dispatcherInstance = Dispatcher :: getInstance ( ) ; $ dispatcherInstance -> dispatch ( "builder.generateAnnotationsStart" ) ; $ publicDir = Config :: getOption ( "publicDir" ) ; $ json = json_encode ( Annotations :: get ( ) ) ; if ( ! is_dir ( $ publicDir . "/annotations" ) ) { mkdir ( $ publicDir . "/annotations" ) ; } file_put_contents ( $ publicDir . "/annotations/annotations.js" , "var comments = " . $ json . ";" ) ; $ dispatcherInstance -> dispatch ( "builder.generateAnnotationsEnd" ) ; }
|
Generates the annotations js file
|
51,650
|
protected function generatePatterns ( $ options = array ( ) ) { $ dispatcherInstance = Dispatcher :: getInstance ( ) ; $ dispatcherInstance -> dispatch ( "builder.generatePatternsStart" ) ; $ exportFiles = ( isset ( $ options [ "exportFiles" ] ) && $ options [ "exportFiles" ] ) ; $ exportDir = Config :: getOption ( "exportDir" ) ; $ patternPublicDir = ! $ exportFiles ? Config :: getOption ( "patternPublicDir" ) : Config :: getOption ( "patternExportDir" ) ; $ patternSourceDir = Config :: getOption ( "patternSourceDir" ) ; $ patternExtension = Config :: getOption ( "patternExtension" ) ; $ suffixRendered = Config :: getOption ( "outputFileSuffixes.rendered" ) ; $ suffixRaw = Config :: getOption ( "outputFileSuffixes.rawTemplate" ) ; $ suffixMarkupOnly = Config :: getOption ( "outputFileSuffixes.markupOnly" ) ; if ( $ exportFiles && ! is_dir ( $ exportDir ) ) { mkdir ( $ exportDir ) ; } if ( ! is_dir ( $ patternPublicDir ) ) { mkdir ( $ patternPublicDir ) ; } $ store = PatternData :: get ( ) ; foreach ( $ store as $ patternStoreKey => $ patternStoreData ) { if ( ( $ patternStoreData [ "category" ] == "pattern" ) && isset ( $ patternStoreData [ "hidden" ] ) && ( ! $ patternStoreData [ "hidden" ] ) ) { $ path = $ patternStoreData [ "pathDash" ] ; $ pathName = ( isset ( $ patternStoreData [ "pseudo" ] ) ) ? $ patternStoreData [ "pathOrig" ] : $ patternStoreData [ "pathName" ] ; $ markup = $ patternStoreData [ "code" ] ; $ markupFull = $ patternStoreData [ "header" ] . $ markup . $ patternStoreData [ "footer" ] ; $ markupEngine = file_get_contents ( $ patternSourceDir . "/" . $ pathName . "." . $ patternExtension ) ; if ( ! is_dir ( $ patternPublicDir . "/" . $ path ) ) { mkdir ( $ patternPublicDir . "/" . $ path ) ; } file_put_contents ( $ patternPublicDir . "/" . $ path . "/" . $ path . $ suffixRendered . ".html" , $ markupFull ) ; if ( ! $ exportFiles ) { file_put_contents ( $ patternPublicDir . "/" . $ path . "/" . $ path . $ suffixMarkupOnly . ".html" , $ markup ) ; file_put_contents ( $ patternPublicDir . "/" . $ path . "/" . $ path . $ suffixRaw . "." . $ patternExtension , $ markupEngine ) ; } } } $ dispatcherInstance -> dispatch ( "builder.generatePatternsEnd" ) ; }
|
Generates all of the patterns and puts them in the public directory
|
51,651
|
protected function generateStyleguide ( ) { $ dispatcherInstance = Dispatcher :: getInstance ( ) ; $ dispatcherInstance -> dispatch ( "builder.generateStyleguideStart" ) ; $ publicDir = Config :: getOption ( "publicDir" ) ; $ ppdExporter = new PatternPathSrcExporter ( ) ; $ patternPathSrc = $ ppdExporter -> run ( ) ; $ options = array ( ) ; $ options [ "patternPaths" ] = $ patternPathSrc ; $ patternEngineBasePath = PatternEngine :: getInstance ( ) -> getBasePath ( ) ; $ patternLoaderClass = $ patternEngineBasePath . "\Loaders\PatternLoader" ; $ patternLoader = new $ patternLoaderClass ( $ options ) ; if ( ! is_dir ( $ publicDir . "/styleguide/" ) ) { mkdir ( $ publicDir . "/styleguide/" ) ; } if ( ! is_dir ( $ publicDir . "/styleguide/html/" ) ) { mkdir ( $ publicDir . "/styleguide/html/" ) ; } $ ppExporter = new PatternPartialsExporter ( ) ; $ partials = $ ppExporter -> run ( ) ; $ patternData = array ( ) ; $ filesystemLoader = Template :: getFilesystemLoader ( ) ; $ stringLoader = Template :: getStringLoader ( ) ; $ globalData = Data :: get ( ) ; $ globalData [ "patternLabHead" ] = $ stringLoader -> render ( array ( "string" => Template :: getHTMLHead ( ) , "data" => array ( "cacheBuster" => $ partials [ "cacheBuster" ] ) ) ) ; $ globalData [ "patternLabFoot" ] = $ stringLoader -> render ( array ( "string" => Template :: getHTMLFoot ( ) , "data" => array ( "cacheBuster" => $ partials [ "cacheBuster" ] , "patternData" => json_encode ( $ patternData ) ) ) ) ; $ globalData [ "viewall" ] = true ; $ header = $ patternLoader -> render ( array ( "pattern" => Template :: getPatternHead ( ) , "data" => $ globalData ) ) ; $ code = $ filesystemLoader -> render ( array ( "template" => "viewall" , "data" => $ partials ) ) ; $ footer = $ patternLoader -> render ( array ( "pattern" => Template :: getPatternFoot ( ) , "data" => $ globalData ) ) ; $ styleGuidePage = $ header . $ code . $ footer ; file_put_contents ( $ publicDir . "/styleguide/html/styleguide.html" , $ styleGuidePage ) ; $ dispatcherInstance -> dispatch ( "builder.generateStyleguideEnd" ) ; }
|
Generates the style guide view
|
51,652
|
public static function updateChangeTime ( ) { if ( is_dir ( Config :: getOption ( "publicDir" ) ) ) { file_put_contents ( Config :: getOption ( "publicDir" ) . "/latest-change.txt" , time ( ) ) ; } else { Console :: writeError ( "the public directory for Pattern Lab doesn't exist..." ) ; } }
|
Write out the time tracking file so the content sync service will work . A holdover from how I put together the original AJAX polling set - up .
|
51,653
|
public function create ( UserInterface $ user ) { if ( $ user == null || $ user -> getAuthIdentifier ( ) == null ) { return false ; } $ token = $ this -> generateAuthToken ( ) ; $ token -> setAuthIdentifier ( $ user -> getAuthIdentifier ( ) ) ; $ t = new \ DateTime ; $ insertData = array_merge ( $ token -> toArray ( ) , array ( 'created_at' => $ t , 'updated_at' => $ t ) ) ; $ this -> db ( ) -> insert ( $ insertData ) ; return $ token ; }
|
Creates an auth token for user .
|
51,654
|
public function find ( $ serializedAuthToken ) { $ authToken = $ this -> deserializeToken ( $ serializedAuthToken ) ; if ( $ authToken == null ) { return null ; } if ( ! $ this -> verifyAuthToken ( $ authToken ) ) { return null ; } $ res = $ this -> db ( ) -> where ( 'auth_identifier' , $ authToken -> getAuthIdentifier ( ) ) -> where ( 'public_key' , $ authToken -> getPublicKey ( ) ) -> where ( 'private_key' , $ authToken -> getPrivateKey ( ) ) -> first ( ) ; if ( $ res == null ) { return null ; } return $ authToken ; }
|
Find user id from auth token .
|
51,655
|
protected static function init ( ) { Timer :: start ( ) ; Console :: init ( ) ; $ baseDir = __DIR__ . "/../../../../../" ; Config :: init ( $ baseDir , false ) ; $ sourceDir = Config :: getOption ( "sourceDir" ) ; if ( ! is_dir ( $ sourceDir ) ) { FileUtil :: makeDir ( $ sourceDir ) ; } $ publicDir = Config :: getOption ( "publicDir" ) ; if ( ! is_dir ( $ publicDir ) ) { FileUtil :: makeDir ( $ publicDir ) ; } Dispatcher :: init ( ) ; }
|
Common init sequence
|
51,656
|
public static function parseComposerExtraList ( $ composerExtra , $ name , $ pathDist ) { if ( isset ( $ composerExtra [ "dist" ] [ "baseDir" ] ) ) { self :: parseFileList ( $ name , $ pathDist , Config :: getOption ( "baseDir" ) , $ composerExtra [ "dist" ] [ "baseDir" ] ) ; } if ( isset ( $ composerExtra [ "dist" ] [ "publicDir" ] ) ) { self :: parseFileList ( $ name , $ pathDist , Config :: getOption ( "publicDir" ) , $ composerExtra [ "dist" ] [ "publicDir" ] ) ; } if ( isset ( $ composerExtra [ "dist" ] [ "sourceDir" ] ) ) { self :: parseFileList ( $ name , $ pathDist , Config :: getOption ( "sourceDir" ) , $ composerExtra [ "dist" ] [ "sourceDir" ] ) ; } if ( isset ( $ composerExtra [ "dist" ] [ "scriptsDir" ] ) ) { self :: parseFileList ( $ name , $ pathDist , Config :: getOption ( "scriptsDir" ) , $ composerExtra [ "dist" ] [ "scriptsDir" ] ) ; } if ( isset ( $ composerExtra [ "dist" ] [ "dataDir" ] ) ) { self :: parseFileList ( $ name , $ pathDist , Config :: getOption ( "dataDir" ) , $ composerExtra [ "dist" ] [ "dataDir" ] ) ; } if ( isset ( $ composerExtra [ "dist" ] [ "componentDir" ] ) ) { $ templateExtension = isset ( $ composerExtra [ "templateExtension" ] ) ? $ composerExtra [ "templateExtension" ] : "mustache" ; $ onready = isset ( $ composerExtra [ "onready" ] ) ? $ composerExtra [ "onready" ] : "" ; $ callback = isset ( $ composerExtra [ "callback" ] ) ? $ composerExtra [ "callback" ] : "" ; $ componentDir = Config :: getOption ( "componentDir" ) ; self :: parseComponentList ( $ name , $ pathDist , $ componentDir . "/" . $ name , $ composerExtra [ "dist" ] [ "componentDir" ] , $ templateExtension , $ onready , $ callback ) ; self :: parseFileList ( $ name , $ pathDist , $ componentDir . "/" . $ name , $ composerExtra [ "dist" ] [ "componentDir" ] ) ; } if ( isset ( $ composerExtra [ "config" ] ) ) { foreach ( $ composerExtra [ "config" ] as $ option => $ value ) { Config :: updateConfigOption ( $ option , $ value ) ; } } }
|
Parse the extra section from composer . json
|
51,657
|
protected static function parseFileList ( $ packageName , $ sourceBase , $ destinationBase , $ fileList ) { foreach ( $ fileList as $ fileItem ) { $ source = self :: removeDots ( key ( $ fileItem ) ) ; $ destination = self :: removeDots ( $ fileItem [ $ source ] ) ; self :: moveFiles ( $ source , $ destination , $ packageName , $ sourceBase , $ destinationBase ) ; } }
|
Move the files from the package to their location in the public dir or source dir
|
51,658
|
protected static function promptStarterKitInstall ( $ starterKitSuggestions ) { Console :: writeLine ( "" ) ; Console :: writeInfo ( "suggested starterkits that work with this edition:" , false , true ) ; foreach ( $ starterKitSuggestions as $ i => $ suggestion ) { $ num = $ i + 1 ; Console :: writeLine ( $ num . ": " . $ suggestion , true ) ; } Console :: writeLine ( "" ) ; $ prompt = "choose an option or hit return to skip:" ; $ options = "(ex. 1)" ; $ input = Console :: promptInput ( $ prompt , $ options , "1" ) ; $ result = ( int ) $ input - 1 ; if ( isset ( $ starterKitSuggestions [ $ result ] ) ) { Console :: writeLine ( "" ) ; $ f = new Fetch ( ) ; $ result = $ f -> fetchStarterKit ( $ starterKitSuggestions [ $ result ] ) ; } }
|
Prompt the user to install a starterkit
|
51,659
|
protected static function packagesInstall ( $ installerInfo , $ event ) { self :: $ isInteractive = $ event -> getIO ( ) -> isInteractive ( ) ; self :: init ( ) ; if ( isset ( $ installerInfo [ "packages" ] ) ) { $ packages = $ installerInfo [ "packages" ] ; $ packages = array_merge ( array_filter ( $ packages , "self::includeStarterKit" ) , array_filter ( $ packages , "self::excludeStarterKit" ) ) ; foreach ( $ packages as $ package ) { $ extra = $ package [ "extra" ] ; $ type = $ package [ "type" ] ; $ name = $ package [ "name" ] ; $ pathBase = $ package [ "pathBase" ] ; $ pathDist = $ package [ "pathDist" ] ; if ( ! empty ( $ extra ) ) { self :: parseComposerExtraList ( $ extra , $ name , $ pathDist ) ; } self :: scanForListener ( $ pathBase ) ; if ( $ type == "patternlab-patternengine" ) { self :: scanForPatternEngineRule ( $ pathBase ) ; } else if ( ( $ type == "patternlab-styleguidekit" ) && ( strpos ( $ name , "-assets-" ) === false ) ) { $ dir = str_replace ( Config :: getOption ( "baseDir" ) , "" , $ pathBase ) ; $ dir = ( $ dir [ strlen ( $ dir ) - 1 ] == DIRECTORY_SEPARATOR ) ? rtrim ( $ dir , DIRECTORY_SEPARATOR ) : $ dir ; Config :: updateConfigOption ( "styleguideKit" , $ name ) ; Config :: updateConfigOption ( "styleguideKitPath" , $ dir ) ; } } } if ( ! empty ( $ installerInfo [ "suggestedStarterKits" ] ) ) { self :: promptStarterKitInstall ( $ installerInfo [ "suggestedStarterKits" ] ) ; } if ( ! empty ( $ installerInfo [ "configOverrides" ] ) ) { foreach ( $ installerInfo [ "configOverrides" ] as $ option => $ value ) { Config :: updateConfigOption ( $ option , $ value , true ) ; } } if ( $ installerInfo [ "projectInstall" ] ) { Console :: writeLine ( "" ) ; Console :: writeLine ( "<h1><fire3>Thank you for installing...</fire3></h1>" , false , true ) ; Console :: writeLine ( "<fire1>( ( </fire1>" ) ; Console :: writeLine ( "<fire2>)\ ) ) ) )\ ) )</fire2>" ) ; Console :: writeLine ( "<fire3>(()/( ) ( /(( /( ( ( (()/( ) ( /(</fire3>" ) ; Console :: writeLine ( "<fire4>/(_)| /( )\())\())))\ )( ( /(_))( /( )\())</fire4>" ) ; Console :: writeLine ( "<fire5>(</fire5><cool>_</cool><fire5>)) )(_)|</fire5><cool>_</cool><fire5>))(</fire5><cool>_</cool><fire5>))//((_|()\ )\ )(</fire5><cool>_</cool><fire5>)) )(_)|(_)\</fire5>" ) ; Console :: writeLine ( "<cool>| _ </cool><fire6>((</fire6><cool>_</cool><fire6>)</fire6><cool>_| |_| |_</cool><fire6>(</fire6><cool>_</cool><fire6>)) ((</fire6><cool>_</cool><fire6>)</fire6><cool>_</cool><fire6>(</fire6><cool>_</cool><fire6>/(</fire6><cool>| | </cool><fire6>((</fire6><cool>_</cool><fire6>)</fire6><cool>_| |</cool><fire6>(</fire6><cool>_</cool><fire6>)</fire6>" ) ; Console :: writeLine ( "<cool>| _/ _` | _| _/ -_)| '_| ' \</cool><fire6>))</fire6><cool> |__/ _` | '_ \ </cool>" ) ; Console :: writeLine ( "<cool>|_| \__,_|\__|\__\ ||_| |_||_|| _\__,_|_.__/ </cool>" , false , true ) ; } }
|
Handle some Pattern Lab specific tasks based on what s found in the package s composer . json file on install
|
51,660
|
public static function packageRemove ( $ packageInfo ) { self :: init ( ) ; self :: scanForListener ( $ packageInfo [ "pathBase" ] , true ) ; if ( $ packageInfo [ "type" ] == "patternlab-patternengine" ) { self :: scanForPatternEngineRule ( $ packageInfo [ "pathBase" ] , true ) ; } $ jsonFile = Config :: getOption ( "componentDir" ) . "/packages/" . str_replace ( "/" , "-" , $ packageInfo [ "name" ] ) . ".json" ; if ( file_exists ( $ jsonFile ) ) { unlink ( $ jsonFile ) ; } }
|
Handle some Pattern Lab specific tasks based on what s found in the package s composer . json file on uninstall
|
51,661
|
protected static function scanForListener ( $ pathPackage , $ remove = false ) { $ pathList = Config :: getOption ( "configDir" ) . "/listeners.json" ; if ( ! file_exists ( $ pathList ) ) { file_put_contents ( $ pathList , "{ \"listeners\": [ ] }" ) ; } $ listenerList = json_decode ( file_get_contents ( $ pathList ) , true ) ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> name ( 'PatternLabListener.php' ) -> in ( $ pathPackage ) ; foreach ( $ finder as $ file ) { $ classes = self :: findClasses ( $ file -> getPathname ( ) ) ; $ listenerName = "\\" . $ classes [ 0 ] ; if ( ! $ remove && ! in_array ( $ listenerName , $ listenerList [ "listeners" ] ) ) { $ listenerList [ "listeners" ] [ ] = $ listenerName ; } else if ( $ remove && in_array ( $ listenerName , $ listenerList [ "listeners" ] ) ) { $ key = array_search ( $ listenerName , $ listenerList [ "listeners" ] ) ; unset ( $ listenerList [ "listeners" ] [ $ key ] ) ; } file_put_contents ( $ pathList , json_encode ( $ listenerList ) ) ; } }
|
Scan the package for a listener
|
51,662
|
protected static function scanForPatternEngineRule ( $ pathPackage , $ remove = false ) { $ pathList = Config :: getOption ( "configDir" ) . "/patternengines.json" ; if ( ! file_exists ( $ pathList ) ) { file_put_contents ( $ pathList , "{ \"patternengines\": [ ] }" ) ; } $ patternEngineList = json_decode ( file_get_contents ( $ pathList ) , true ) ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> name ( "PatternEngineRule.php" ) -> in ( $ pathPackage ) ; foreach ( $ finder as $ file ) { $ classes = self :: findClasses ( $ file -> getPathname ( ) ) ; $ patternEngineName = "\\" . $ classes [ 0 ] ; if ( ! $ remove && ! in_array ( $ patternEngineName , $ patternEngineList [ "patternengines" ] ) ) { $ patternEngineList [ "patternengines" ] [ ] = $ patternEngineName ; } else if ( $ remove && in_array ( $ patternEngineName , $ patternEngineList [ "patternengines" ] ) ) { $ key = array_search ( $ patternEngineName , $ patternEngineList [ "patternengines" ] ) ; unset ( $ patternEngineList [ "patternengines" ] [ $ key ] ) ; } file_put_contents ( $ pathList , json_encode ( $ patternEngineList ) ) ; } }
|
Scan the package for a pattern engine rule
|
51,663
|
public function setSlugAttribute ( $ value ) { array_set ( $ this -> attributes , $ this -> getSlugKey ( ) , $ this -> makeSlug ( $ value ) ) ; }
|
Mutate the value to a slug format and assign to the sluggable key .
|
51,664
|
public static function checkPathFromConfig ( $ path , $ configPath , $ configOption = "" ) { if ( ! isset ( $ path ) ) { Console :: writeError ( "please make sure " . $ configOption . " is set in <path>" . Console :: getHumanReadablePath ( $ configPath ) . "</path> by adding '" . $ configOption . "=some/path'. sorry, stopping pattern lab... :(" ) ; } else if ( ! is_dir ( $ path ) ) { Console :: writeWarning ( "i can't seem to find the directory <path>" . Console :: getHumanReadablePath ( $ path ) . "</path>..." ) ; self :: makeDir ( $ path ) ; Console :: writeWarning ( "i created <path>" . Console :: getHumanReadablePath ( $ path ) . "</path> just in case. you can edit this in <path>" . Console :: getHumanReadablePath ( $ configPath ) . "</path> by editing " . $ configOption . "..." ) ; } }
|
Check that a dir from the config exists and try to build it if needed
|
51,665
|
public static function makeDir ( $ dir ) { $ fs = new Filesystem ( ) ; try { $ fs -> mkdir ( $ dir ) ; } catch ( IOExceptionInterface $ e ) { Console :: writeError ( "an error occurred while creating your directory at <path>" . $ e -> getPath ( ) . "</path>..." ) ; } unset ( $ fs ) ; }
|
Make a directory
|
51,666
|
protected static function moveFile ( $ s , $ p ) { $ sourceDir = Config :: getOption ( "sourceDir" ) ; $ publicDir = Config :: getOption ( "publicDir" ) ; $ fs = new Filesystem ( ) ; $ fs -> copy ( $ sourceDir . DIRECTORY_SEPARATOR . $ s , $ publicDir . DIRECTORY_SEPARATOR . $ p ) ; }
|
Copies a file from the given source path to the given public path . THIS IS NOT FOR PATTERNS
|
51,667
|
public static function moveStaticFile ( $ fileName , $ copy = "" , $ find = "" , $ replace = "" ) { self :: moveFile ( $ fileName , str_replace ( $ find , $ replace , $ fileName ) ) ; Util :: updateChangeTime ( ) ; if ( $ copy != "" ) { Console :: writeInfo ( $ fileName . " " . $ copy . "..." ) ; } }
|
Moves static files that aren t directly related to Pattern Lab
|
51,668
|
public static function getCommand ( ) { foreach ( self :: $ commands as $ command => $ attributes ) { if ( isset ( self :: $ options [ $ command ] ) || isset ( self :: $ options [ $ attributes [ "commandShort" ] ] ) ) { return $ command ; } } return false ; }
|
Return the command that was given in the command line arguments
|
51,669
|
public static function getPathPHP ( ) { $ manualPHP = Config :: getOption ( "phpBin" ) ; $ autoPHP = new PhpExecutableFinder ( ) ; $ path = $ manualPHP ? $ manualPHP : $ autoPHP -> find ( ) ; if ( ! $ path ) { $ configPath = Console :: getHumanReadablePath ( Config :: getOption ( "configPath" ) ) ; $ examplePHP = ( DIRECTORY_SEPARATOR === "/" ) ? "C:\wamp\bin\php\php5.5.12" : "/opt/local/lib/php54" ; Console :: writeError ( "can't find PHP. add the path to PHP by adding the option \"phpBin\" to <path>" . $ configPath . "</path>. it should look like \"phpBin\": \"" . $ examplePHP . "\"" ) ; } return $ path ; }
|
Get the path to PHP binary
|
51,670
|
public static function setCommand ( $ long , $ desc , $ help , $ short = "" ) { if ( ! empty ( $ short ) ) { self :: $ optionsShort .= $ short ; } self :: $ optionsLong [ ] = $ long ; $ short = str_replace ( ":" , "" , $ short ) ; $ long = str_replace ( ":" , "" , $ long ) ; self :: $ commands [ $ long ] = array ( "commandShort" => $ short , "commandLong" => $ long , "commandLongLength" => strlen ( $ long ) , "commandDesc" => $ desc , "commandHelp" => $ help , "commandOptions" => array ( ) , "commandExamples" => array ( ) ) ; }
|
Set - up the command so it can be used from the command line
|
51,671
|
public static function setCommandSample ( $ command , $ sample , $ extra ) { $ command = str_replace ( ":" , "" , $ command ) ; self :: $ commands [ $ command ] [ "commandExamples" ] [ ] = array ( "exampleSample" => $ sample , "exampleExtra" => $ extra ) ; }
|
Set a sample for a specific command
|
51,672
|
public static function setCommandOption ( $ command , $ long , $ desc , $ sample , $ short = "" , $ extra = "" ) { if ( ( $ short != "" ) && ( $ short != "z" ) && ( strpos ( self :: $ optionsShort , $ short ) === false ) ) { self :: $ optionsShort .= $ short ; } if ( ! in_array ( $ long , self :: $ optionsLong ) ) { self :: $ optionsLong [ ] = $ long ; } $ short = str_replace ( ":" , "" , $ short ) ; $ long = str_replace ( ":" , "" , $ long ) ; if ( $ short == "z" ) { $ short = "z" . self :: $ zTracker ; self :: $ zTracker ++ ; } self :: $ commands [ $ command ] [ "commandOptions" ] [ $ long ] = array ( "optionShort" => $ short , "optionLong" => $ long , "optionLongLength" => strlen ( $ long ) , "optionDesc" => $ desc , "optionSample" => $ sample , "optionExtra" => $ extra ) ; }
|
Set - up an option for a given command so it can be used from the command line
|
51,673
|
public static function writeHelp ( ) { $ lengthLong = 0 ; foreach ( self :: $ commands as $ command => $ attributes ) { $ lengthLong = ( $ attributes [ "commandLongLength" ] > $ lengthLong ) ? $ attributes [ "commandLongLength" ] : $ lengthLong ; } self :: writeLine ( "" ) ; self :: writeLine ( "<h1>Pattern Lab Console Options</h1>" , true , true ) ; self :: writeLine ( "<h2>Usage</h2>:" , true , true ) ; self :: writeLine ( " php " . self :: $ self . " command <optional>[options]</optional>" , true , true ) ; self :: writeLine ( "<h2>Available commands</h2>:" , true , true ) ; foreach ( self :: $ commands as $ command => $ attributes ) { $ spacer = self :: getSpacer ( $ lengthLong , $ attributes [ "commandLongLength" ] ) ; self :: writeLine ( " --" . $ attributes [ "commandLong" ] . $ spacer . " <desc>" . $ attributes [ "commandDesc" ] . "</desc>" , true ) ; } self :: writeLine ( "" ) ; self :: writeLine ( "<h2>Get options for a specific command:</h2>" , true , true ) ; self :: writeLine ( " php " . self :: $ self . " --help --command" , true ) ; self :: writeLine ( "" ) ; }
|
Write out the generic help
|
51,674
|
public static function getSpacer ( $ lengthLong , $ itemLongLength ) { $ i = 0 ; $ spacer = " " ; $ spacerLength = $ lengthLong - $ itemLongLength ; while ( $ i < $ spacerLength ) { $ spacer .= " " ; $ i ++ ; } return $ spacer ; }
|
Make sure the space is properly set between long command options and short command options
|
51,675
|
public static function addTags ( $ line , $ tag ) { $ lineFinal = "<" . $ tag . ">" . preg_replace ( "/<[A-z0-9-_]{1,}>[^<]{1,}<\/[A-z0-9-_]{1,}>/" , "</" . $ tag . ">$0<" . $ tag . ">" , $ line ) . "</" . $ tag . ">" ; return $ lineFinal ; }
|
Modify a line to include the given tag by default
|
51,676
|
public static function writeError ( $ line , $ doubleSpace = false , $ doubleBreak = false ) { $ lineFinal = self :: addTags ( $ line , "error" ) ; self :: writeLine ( $ lineFinal , $ doubleSpace , $ doubleBreak ) ; exit ( 1 ) ; }
|
Write out a line to the console with error tags . It forces an exit of the script
|
51,677
|
public static function writeInfo ( $ line , $ doubleSpace = false , $ doubleBreak = false ) { $ lineFinal = self :: addTags ( $ line , "info" ) ; self :: writeLine ( $ lineFinal , $ doubleSpace , $ doubleBreak ) ; }
|
Write out a line to the console with info tags
|
51,678
|
public static function log ( $ line , $ doubleSpace = false , $ doubleBreak = false ) { self :: writeInfo ( $ line , $ doubleSpace = false , $ doubleBreak = false ) ; }
|
Alias for writeInfo because I keep wanting to use it
|
51,679
|
public static function writeLine ( $ line , $ doubleSpace = false , $ doubleBreak = false ) { $ break = ( $ doubleBreak ) ? PHP_EOL . PHP_EOL : PHP_EOL ; if ( strpos ( $ line , "<nophpeol>" ) !== false ) { $ break = "" ; $ line = str_replace ( "<nophpeol>" , "" , $ line ) ; } $ space = ( $ doubleSpace ) ? " " : "" ; $ c = self :: $ color ; print $ space . $ c ( $ line ) -> colorize ( ) . $ break ; }
|
Write out a line to the console
|
51,680
|
public static function writeTag ( $ tag , $ line , $ doubleSpace = false , $ doubleBreak = false ) { $ lineFinal = self :: addTags ( $ line , $ tag ) ; self :: writeLine ( $ lineFinal , $ doubleSpace , $ doubleBreak ) ; }
|
Write out a line to the console with a specific tag
|
51,681
|
protected static function loadListeners ( ) { $ configDir = Config :: getOption ( "configDir" ) ; if ( file_exists ( $ configDir . "/listeners.json" ) ) { $ listenerList = json_decode ( file_get_contents ( $ configDir . "/listeners.json" ) , true ) ; foreach ( $ listenerList [ "listeners" ] as $ listenerName ) { if ( $ listenerName [ 0 ] != "_" ) { $ listener = new $ listenerName ( ) ; $ listeners = $ listener -> getListeners ( ) ; foreach ( $ listeners as $ event => $ eventProps ) { $ eventPriority = ( isset ( $ eventProps [ "priority" ] ) ) ? $ eventProps [ "priority" ] : 0 ; self :: $ instance -> addListener ( $ event , array ( $ listener , $ eventProps [ "callable" ] ) , $ eventPriority ) ; } } } } }
|
Load listeners that may be a part of plug - ins that should be notified by the dispatcher
|
51,682
|
protected function getDynamicRelationship ( $ name ) { if ( $ this -> isRelationship ( $ name ) ) { if ( array_key_exists ( $ name , $ this -> getRelations ( ) ) ) { return $ this -> getRelation ( $ name ) ; } return $ this -> getRelationshipFromMethod ( $ name , camel_case ( $ name ) ) ; } }
|
Get a dynamically resolved relationship .
|
51,683
|
public function getRelationship ( $ name ) { if ( ! $ this -> isRelationship ( $ name ) ) { $ exception = new ModelNotFoundException ( ) ; $ exception -> setModel ( $ name ) ; throw $ exception ; } return $ this -> relationships [ $ name ] ; }
|
Return the relationship configurations .
|
51,684
|
protected function callRelationship ( $ name ) { $ args = $ this -> getRelationship ( $ name ) ; $ method = array_shift ( $ args ) ; $ relationship = call_user_func_array ( [ $ this , $ method ] , $ args ) ; if ( $ this -> hasPivotAttributes ( $ name ) ) { $ attributes = $ this -> getPivotAttributes ( $ name ) ; if ( in_array ( 'timestamps' , $ attributes ) ) { unset ( $ attributes [ array_search ( 'timestamps' , $ attributes ) ] ) ; $ relationship -> withTimestamps ( ) ; } $ relationship -> withPivot ( $ attributes ) ; } return $ relationship ; }
|
Proxy call a relationship method using the configuration arguments of the relationship .
|
51,685
|
public function scopeWithout ( $ query , $ relations ) { $ relations = is_array ( $ relations ) ? $ relations : array_slice ( func_get_args ( ) , 1 ) ; $ relationships = array_dot ( $ query -> getEagerLoads ( ) ) ; foreach ( $ relations as $ relation ) { unset ( $ relationships [ $ relation ] ) ; } return $ query -> setEagerLoads ( [ ] ) -> with ( array_keys ( $ relationships ) ) ; }
|
Set the relationships that should not be eager loaded .
|
51,686
|
public function generate ( $ options = array ( ) ) { if ( empty ( $ options ) ) { Console :: writeError ( "need to pass options to generate..." ) ; } $ moveStatic = ( isset ( $ options [ "moveStatic" ] ) ) ? $ options [ "moveStatic" ] : true ; $ noCacheBuster = ( isset ( $ options [ "noCacheBuster" ] ) ) ? $ options [ "noCacheBuster" ] : false ; $ exportFiles = ( isset ( $ options [ "exportFiles" ] ) ) ? $ options [ "exportFiles" ] : false ; $ exportClean = ( isset ( $ options [ "exportClean" ] ) ) ? $ options [ "exportClean" ] : false ; $ watchMessage = ( isset ( $ options [ "watchMessage" ] ) ) ? $ options [ "watchMessage" ] : false ; $ watchVerbose = ( isset ( $ options [ "watchVerbose" ] ) ) ? $ options [ "watchVerbose" ] : false ; if ( $ noCacheBuster ) { Config :: setOption ( "cacheBuster" , 0 ) ; } Data :: gather ( ) ; $ options = array ( ) ; $ options [ "exportClean" ] = $ exportClean ; $ options [ "exportFiles" ] = $ exportFiles ; PatternData :: gather ( $ options ) ; Annotations :: gather ( ) ; if ( ( Config :: getOption ( "cleanPublic" ) == "true" ) && $ moveStatic ) { FileUtil :: cleanPublic ( ) ; } $ this -> generateIndex ( ) ; $ this -> generateStyleguide ( ) ; $ this -> generateViewAllPages ( ) ; $ options = array ( ) ; $ options [ "exportFiles" ] = $ exportFiles ; $ this -> generatePatterns ( $ options ) ; $ this -> generateAnnotations ( ) ; if ( $ moveStatic ) { $ this -> moveStatic ( ) ; } Util :: updateChangeTime ( ) ; if ( $ watchVerbose && $ watchMessage ) { Console :: writeLine ( $ watchMessage ) ; } else { Console :: writeLine ( "your site has been generated..." ) ; Timer :: stop ( ) ; } }
|
Pulls together a bunch of functions from builder . lib . php in an order that makes sense
|
51,687
|
public static function configure ( ) { $ config = \ BoletoSimples :: $ configuration ; $ oauth2 = new Oauth2Subscriber ( ) ; $ oauth2 -> setAccessToken ( $ config -> access_token ) ; self :: $ client = new Client ( [ 'base_url' => $ config -> baseUri ( ) , 'defaults' => [ 'headers' => [ 'User-Agent' => $ config -> userAgent ( ) ] , 'auth' => 'oauth2' , 'subscribers' => [ $ oauth2 ] ] , 'verify' => false ] ) ; self :: $ default_options = [ 'headers' => [ 'Content-Type' => 'application/json' ] , 'exceptions' => false ] ; }
|
Configure the GuzzleHttp \ Client with default options .
|
51,688
|
protected function getDynamicEncrypted ( $ attribute ) { if ( $ this -> isEncryptable ( $ attribute ) ) { if ( $ this -> isEncrypted ( $ attribute ) ) { return $ this -> getEncryptedAttribute ( $ attribute ) ; } } }
|
Get an encrypted attribute dynamically .
|
51,689
|
protected function setDynamicEncryptable ( $ attribute , $ value ) { if ( $ this -> isEncryptable ( $ attribute ) ) { if ( $ this -> isDecrypted ( $ attribute ) ) { $ this -> setEncryptingAttribute ( $ attribute , $ value ) ; return true ; } } return false ; }
|
Set an encryptable attribute dynamically .
|
51,690
|
public function isEncrypted ( $ attribute ) { if ( ! array_key_exists ( $ attribute , $ this -> attributes ) ) { return false ; } try { $ this -> decrypt ( array_get ( $ this -> attributes , $ attribute ) ) ; } catch ( DecryptException $ exception ) { return false ; } return true ; }
|
Returns whether the attribute is encrypted .
|
51,691
|
public function encryptAttributes ( ) { foreach ( $ this -> getEncryptable ( ) as $ attribute ) { $ this -> setEncryptingAttribute ( $ attribute , array_get ( $ this -> attributes , $ attribute ) ) ; } }
|
Encrypt attributes that should be encrypted .
|
51,692
|
public function getEncryptedAttribute ( $ attribute ) { $ value = array_get ( $ this -> attributes , $ attribute ) ; return $ this -> isEncrypted ( $ attribute ) ? $ this -> decrypt ( $ value ) : $ value ; }
|
Get the decrypted value for an encrypted attribute .
|
51,693
|
public function setEncryptingAttribute ( $ attribute , $ value ) { array_set ( $ this -> attributes , $ attribute , $ this -> encrypt ( $ value ) ) ; }
|
Set an encrypted value for an encryptable attribute .
|
51,694
|
public function migrate ( $ diffVersion = false ) { $ migrations = new \ DirectoryIterator ( __DIR__ . "/../../migrations/" ) ; $ migrationsValid = array ( ) ; foreach ( $ migrations as $ migration ) { $ filename = $ migration -> getFilename ( ) ; if ( ! $ migration -> isDot ( ) && $ migration -> isFile ( ) && ( $ filename [ 0 ] != "_" ) ) { $ migrationsValid [ ] = $ filename ; } } asort ( $ migrationsValid ) ; foreach ( $ migrationsValid as $ filename ) { $ basePath = __DIR__ . "/../../../" ; $ migrationData = json_decode ( file_get_contents ( __DIR__ . "/../../migrations/" . $ filename ) ) ; $ checkType = $ migrationData -> checkType ; $ sourcePath = ( $ checkType == "fileExists" ) ? $ basePath . $ migrationData -> sourcePath : $ basePath . $ migrationData -> sourcePath . DIRECTORY_SEPARATOR ; $ destinationPath = ( $ checkType == "fileExists" ) ? $ basePath . $ migrationData -> destinationPath : $ basePath . $ migrationData -> destinationPath . DIRECTORY_SEPARATOR ; if ( $ checkType == "dirEmpty" ) { $ emptyDir = true ; $ objects = new \ DirectoryIterator ( $ destinationPath ) ; foreach ( $ objects as $ object ) { if ( ! $ object -> isDot ( ) && ( $ object -> getFilename ( ) != "README" ) && ( $ object -> getFilename ( ) != ".DS_Store" ) ) { $ emptyDir = false ; } } if ( $ emptyDir ) { $ this -> runMigration ( $ filename , $ sourcePath , $ destinationPath , false ) ; } } else if ( $ checkType == "dirExists" ) { if ( ! is_dir ( $ destinationPath ) ) { mkdir ( $ destinationPath ) ; } } else if ( $ checkType == "fileExists" ) { if ( ! file_exists ( $ destinationPath ) ) { $ this -> runMigration ( $ filename , $ sourcePath , $ destinationPath , true ) ; } } else if ( ( $ checkType == "versionDiffDir" ) && $ diffVersion ) { if ( ! is_dir ( $ destinationPath ) ) { mkdir ( $ destinationPath ) ; } $ this -> runMigration ( $ filename , $ sourcePath , $ destinationPath , false ) ; } else if ( ( $ checkType == "versionDiffFile" ) && $ diffVersion ) { $ this -> runMigration ( $ filename , $ sourcePath , $ destinationPath , true ) ; } else { print "pattern Lab doesn't recognize a checkType of " . $ checkType . ". The migrator class is pretty thin at the moment.\n" ; exit ; } } }
|
Read through the migrations and move files as needed
|
51,695
|
public function attributesToCarbon ( $ event ) { foreach ( $ this -> attributes as $ attribute ) { $ value = $ this -> owner -> $ attribute ; if ( ! empty ( $ value ) ) { if ( is_numeric ( $ value ) ) { $ this -> owner -> $ attribute = Carbon :: createFromTimestamp ( $ value ) ; } elseif ( preg_match ( '/^(\d{4})-(\d{2})-(\d{2})$/' , $ value ) ) { $ this -> owner -> $ attribute = Carbon :: createFromFormat ( 'Y-m-d' , $ value ) -> startOfDay ( ) ; } else { $ this -> owner -> $ attribute = Carbon :: createFromFormat ( $ this -> dateFormat , $ this -> owner -> $ attribute ) ; } } } }
|
Convert the model s attributes to an Carbon instance .
|
51,696
|
public function attributesToDefaultFormat ( $ event ) { $ oldAttributes = $ this -> owner -> oldAttributes ; foreach ( $ this -> attributes as $ attribute ) { $ oldAttributeValue = $ oldAttributes [ $ attribute ] ; if ( $ this -> owner -> $ attribute instanceof Carbon ) { if ( is_numeric ( $ oldAttributeValue ) ) { $ this -> owner -> $ attribute = $ this -> owner -> $ attribute -> timestamp ; } } } }
|
Handles owner beforeUpdate event for converting attributes values to the default format
|
51,697
|
protected function getDynamicJuggle ( $ key , $ value ) { if ( $ this -> isJugglable ( $ key ) ) { return $ this -> juggle ( $ value , $ this -> getJuggleType ( $ key ) ) ; } return $ value ; }
|
If juggling is active it returns the juggleAttribute . If not it just returns the value as it was passed .
|
51,698
|
protected function setDynamicJuggle ( $ key , $ value ) { if ( ! is_null ( $ value ) && $ this -> isJugglable ( $ key ) ) { $ this -> juggleAttribute ( $ key , $ value ) ; } }
|
If juggling is active it sets the attribute in the model by type juggling the value first .
|
51,699
|
public function setJugglable ( array $ attributes ) { foreach ( $ attributes as $ attribute => $ type ) { $ this -> checkJuggleType ( $ type ) ; } $ this -> jugglable = $ attributes ; }
|
Set the jugglable attributes .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.