idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
58,300
|
public function andThrow ( $ e ) { if ( ! $ e instanceof \ Exception ) { if ( is_scalar ( $ e ) && class_exists ( $ e ) && is_a ( $ e , '\Exception' , true ) ) { $ e = new $ e ( "Generic message" ) ; } else { throw new \ LogicException ( "Can only create exceptions on-the-fly with a scalar message" ) ; } } $ this -> andReturn ( function ( ) use ( $ e ) { if ( ! $ e instanceof \ Exception ) { throw new \ Exception ( $ e ) ; } else { throw $ e ; } } ) ; return $ this ; }
|
Throw the provided expectation when called .
|
58,301
|
public function andReturnValues ( array $ returnValues ) { $ this -> andReturn ( function ( ) use ( & $ returnValues ) { if ( count ( $ returnValues ) > 1 ) { return array_shift ( $ returnValues ) ; } else { return current ( $ returnValues ) ; } } ) ; return $ this ; }
|
Return each of the specified values on consecutive calls .
|
58,302
|
public function times ( $ times = null ) { if ( $ this -> atLeastWasCalled && $ times !== null ) { $ this -> atLeastWasCalled = false ; $ this -> atLeast ( $ times ) ; } elseif ( $ times !== null ) { if ( $ times === 0 ) { $ this -> never ( ) ; } else { $ count = 0 ; $ this -> expectation -> setPostPerformCallback ( function ( ) use ( & $ count , $ times ) { $ count ++ ; $ this -> commentBuilder -> incrementCallCount ( ) ; if ( $ count === $ times ) { $ this -> expectation -> setSatisfied ( true ) ; $ this -> expectation -> setPerformCallback ( function ( $ name , $ args ) use ( $ times ) { $ message = "Unexpected call to {$this->methodName}" ; if ( count ( $ args ) ) { $ message .= " with " . Util :: printArray ( $ args ) ; } $ message .= " - already called $times times" ; throw new UnexpectedCallException ( $ message ) ; } ) ; } } ) ; $ this -> commentBuilder -> setTimes ( $ times ) ; $ this -> commentBuilder -> setAtLeast ( false ) ; } } return $ this ; }
|
The method should be called this number of times .
|
58,303
|
public function atLeast ( $ times = null ) { if ( $ times === null ) { $ this -> atLeastWasCalled = true ; } else { $ count = 0 ; $ this -> expectation -> setPostPerformCallback ( function ( ) use ( & $ count , $ times ) { $ this -> commentBuilder -> incrementCallCount ( ) ; $ count ++ ; if ( $ count >= $ times ) { $ this -> expectation -> setSatisfied ( true ) ; } } ) ; if ( $ times === 0 ) { $ this -> expectation -> setSatisfied ( true ) ; } $ this -> commentBuilder -> setTimes ( $ times ) ; $ this -> commentBuilder -> setAtLeast ( true ) ; } return $ this ; }
|
The method should be called at least this many times .
|
58,304
|
public function registerDecoder ( DecoderInterface $ decoder ) { if ( ! in_array ( $ decoder , $ this -> decoders ) ) { $ this -> decoders [ ] = $ decoder ; } }
|
Register a decoder in this chain
|
58,305
|
public function getJSONString ( ) { $ json = '{' . '"@context":"' . SocialRecord :: JSONLD_CONTEXT . '",' . '"@type":"' . SocialRecord :: JSONLD_TYPE . '",' . '"type":"' . $ this -> type . '",' . '"globalID":"' . $ this -> globalID . '",' . '"platformGID":"' . $ this -> platformGID . '",' . '"displayName":"' . $ this -> displayName . '",' . '"profileLocation":"' . $ this -> profileLocation . '",' . '"personalPublicKey":"' . PublicKey :: exportKey ( $ this -> personalPublicKey ) . '",' . '"accountPublicKey":"' . PublicKey :: exportKey ( $ this -> accountPublicKey ) . '",' . '"salt":"' . $ this -> salt . '",' . '"datetime":"' . $ this -> datetime . '",' . '"active":' . $ this -> active . ',' . '"keyRevocationList":[' ; foreach ( $ this -> keyRevocationList as $ krc ) { $ json .= $ krc -> getJSONString ( ) ; if ( $ krc !== end ( $ this -> keyRevocationList ) ) $ json .= ',' ; } $ json .= ']}' ; return $ json ; }
|
Serialization method for SocialRecord
|
58,306
|
public function verify ( ) { if ( $ this -> type != SocialRecord :: TYPE_PLATFORM && $ this -> type != SocialRecord :: TYPE_USER && $ this -> type != SocialRecord :: TYPE_PAGE ) throw new SocialRecordFormatException ( 'invalid type value [' . $ this -> type . ']' ) ; if ( ! GID :: isValid ( $ this -> globalID ) ) throw new SocialRecordFormatException ( 'invalid globalID value' ) ; if ( ! GID :: isValid ( $ this -> platformGID ) ) throw new SocialRecordFormatException ( 'invalid platformGID value' ) ; if ( ! GID :: verifyGID ( $ this -> personalPublicKey , $ this -> salt , $ this -> globalID ) ) throw new SocialRecordFormatException ( 'invalid globalID value' ) ; if ( ! XSDDateTime :: isValid ( $ this -> datetime ) ) throw new SocialRecordFormatException ( 'invalid date value [' . $ this -> datetime . ']' ) ; return true ; }
|
Runs a validation of the structure of the SocialRecord
|
58,307
|
public function after ( $ expression = null , $ test = false , $ limit = LIMIT_AFTER ) { if ( isset ( $ this -> after ) && $ limit == LIMIT_AFTER ) { $ after = $ this -> after ; } else { $ after = substr ( $ this -> data , $ this -> end , $ this -> end + $ limit ) ; $ this -> after = $ after ; } if ( $ test === false ) { if ( $ expression === null ) { return new Token ( substr ( $ this -> data , $ this -> end ) , $ this -> end ) ; } preg_match ( $ expression , $ after , $ match , PREG_OFFSET_CAPTURE ) ; if ( ! isset ( $ match [ 0 ] [ 0 ] ) || ! isset ( $ match [ 0 ] [ 1 ] ) ) return null ; return new Token ( $ match [ 0 ] [ 0 ] , $ match [ 0 ] [ 1 ] + $ this -> end ) ; } else { if ( $ expression === null ) { return $ this -> end < $ this -> size ; } return ( boolean ) preg_match ( $ expression , $ after ) ; } }
|
Perform a forwards search of the data and return a Token representing the expression matched and its position .
|
58,308
|
public function before ( $ expression = null , $ test = false , $ limit = LIMIT_BEFORE ) { if ( isset ( $ this -> before ) && $ limit == LIMIT_BEFORE ) { $ before = $ this -> before ; } else { $ limit = max ( 0 , $ this -> begin - $ limit ) ; $ before = substr ( $ this -> data , $ limit , $ this -> begin - $ limit ) ; $ this -> before = $ before ; } if ( $ test === false ) { if ( $ expression === null ) { return new Token ( $ before , $ this -> begin ) ; } preg_match ( $ expression , $ before , $ match , PREG_OFFSET_CAPTURE ) ; if ( ! isset ( $ match [ 0 ] [ 0 ] ) || ! isset ( $ match [ 0 ] [ 1 ] ) ) return null ; return new Token ( $ match [ 0 ] [ 0 ] , $ match [ 0 ] [ 1 ] + $ limit ) ; } else { if ( $ expression === null ) { return $ this -> begin > 0 ; } return ( boolean ) preg_match ( $ expression , $ before ) ; } }
|
Perform a backwards search of the data and return a Token representing the expression matched and its position .
|
58,309
|
public function move ( Token $ token ) { $ this -> begin = $ token -> begin ; $ this -> end = $ token -> end ; unset ( $ this -> after , $ this -> before ) ; }
|
Move the internal cursor to the position of a token .
|
58,310
|
public static function find ( $ code ) { $ code = strtoupper ( $ code ) ; $ currencies = static :: all ( ) ; if ( isset ( $ currencies [ $ code ] ) ) { return new static ( $ code , $ currencies [ $ code ] [ 'numeric' ] , $ currencies [ $ code ] [ 'decimals' ] ) ; } return null ; }
|
Find a specific currency
|
58,311
|
public function _add_sns_account_fields ( $ user_contactmethods = [ ] ) { $ sns_accounts = $ this -> _sns_accounts ( ) ; unset ( $ sns_accounts [ 'url' ] ) ; $ user_contactmethods = array_merge ( $ user_contactmethods , $ sns_accounts ) ; return $ user_contactmethods ; }
|
Adds sns account fields
|
58,312
|
protected function _sns_accounts ( ) { $ user_contactmethods = apply_filters ( 'inc2734_wp_profile_box_sns_accounts' , [ 'url' => __ ( 'Web Site' , 'inc2734-wp-profile-box' ) , 'twitter' => __ ( 'Twitter' , 'inc2734-wp-profile-box' ) , 'facebook' => __ ( 'Facebook' , 'inc2734-wp-profile-box' ) , 'instagram' => __ ( 'Instagram' , 'inc2734-wp-profile-box' ) , 'youtube' => __ ( 'YouTube' , 'inc2734-wp-profile-box' ) , 'linkedin' => __ ( 'Linkedin' , 'inc2734-wp-profile-box' ) , 'wordpress' => __ ( 'WordPress' , 'inc2734-wp-profile-box' ) , 'tumblr' => __ ( 'Tumblr' , 'inc2734-wp-profile-box' ) , ] ) ; return $ user_contactmethods ; }
|
Adds SNS accounts settings
|
58,313
|
protected function _get_detail_page_url ( $ user_id ) { $ detail_keys = $ this -> _add_detail_url_field ( ) ; $ detail_keys = array_keys ( $ detail_keys ) ; foreach ( $ detail_keys as $ key ) { $ detail_url = get_the_author_meta ( $ key , $ user_id ) ; if ( $ detail_url ) { return $ detail_url ; } } }
|
Returns detail page URL
|
58,314
|
protected function _get_sns_accounts ( $ user_id ) { $ sns_accounts = $ this -> _sns_accounts ( ) ; $ sns_account_keys = array_keys ( $ sns_accounts ) ; $ sns_accounts = [ ] ; foreach ( $ sns_account_keys as $ sns_account_key ) { $ sns_account = get_the_author_meta ( $ sns_account_key , $ user_id ) ; if ( ! $ sns_account ) { continue ; } $ sns_accounts [ $ sns_account_key ] = $ sns_account ; } return $ sns_accounts ; }
|
Returns SNS account URLs
|
58,315
|
private function parseFile ( string $ path ) : array { $ json = json_decode ( file_get_contents ( $ path ) , true ) ; $ root = dirname ( $ path ) ; $ namespaces = array_merge ( iterator_to_array ( $ this -> parseNamespaces ( $ json [ 'autoload' ] [ 'psr-4' ] ? : [ ] , $ root ) ) , iterator_to_array ( $ this -> parseNamespaces ( $ json [ 'autoload-dev' ] [ 'psr-4' ] ? : [ ] , $ root ) ) ) ; return $ namespaces ; }
|
Parses namespaces from a composer . json file .
|
58,316
|
private function parseNamespaces ( array $ config , string $ root ) : Generator { foreach ( $ config as $ name => $ paths ) { $ paths = is_array ( $ paths ) ? $ paths : [ $ paths ] ; foreach ( $ paths as $ path ) { $ path = realpath ( $ root . '/' . $ path ) ; if ( ! $ path ) { continue ; } yield new Psr4Namespace ( $ name , $ path ) ; } } }
|
Parses namespaces from a configuration section .
|
58,317
|
public function Base_AfterCommentFormat_Handler ( $ Sender ) { if ( ! C ( 'Plugins.Emotify.FormatEmoticons' , TRUE ) ) return ; $ Object = $ Sender -> EventArguments [ 'Object' ] ; $ Object -> FormatBody = $ this -> DoEmoticons ( $ Object -> FormatBody ) ; $ Sender -> EventArguments [ 'Object' ] = $ Object ; }
|
Replace emoticons in comments .
|
58,318
|
public function PostController_AfterCommentPreviewFormat_Handler ( $ Sender ) { if ( ! C ( 'Plugins.Emotify.FormatEmoticons' , TRUE ) ) return ; $ Sender -> Comment -> Body = $ this -> DoEmoticons ( $ Sender -> Comment -> Body ) ; }
|
Replace emoticons in comment preview .
|
58,319
|
private function _EmotifySetup ( $ Sender ) { $ Sender -> AddJsFile ( 'emotify.js' , 'plugins/Emotify' ) ; $ Emoticons = array ( ) ; foreach ( $ this -> GetEmoticons ( ) as $ i => $ gif ) { if ( ! isset ( $ Emoticons [ $ gif ] ) ) $ Emoticons [ $ gif ] = $ i ; } $ Emoticons = array_flip ( $ Emoticons ) ; $ Sender -> AddDefinition ( 'Emoticons' , base64_encode ( json_encode ( $ Emoticons ) ) ) ; }
|
Prepare a page to be emotified .
|
58,320
|
public function dateFormat ( $ date , string $ format = 'M d Y' ) : string { if ( $ date instanceof DateTime ) { return $ date -> format ( $ format ) ; } elseif ( is_int ( $ date ) ) { return date ( $ format , $ date ) ; } return date ( $ format , strtotime ( $ date ) ) ; }
|
Return a formatted date string .
|
58,321
|
public function paginate ( Paginator $ model ) : string { return with ( new SemanticUIPagination ( $ model -> appends ( $ this -> request -> query ( ) ) ) ) -> render ( ) ; }
|
Use a custom pagination style .
|
58,322
|
public function set ( string $ key , $ value ) : Definition { $ this -> data [ $ key ] = $ value ; return $ this ; }
|
Set a value for the given key .
|
58,323
|
public function get ( string $ key ) { if ( ! $ this -> has ( $ key ) ) { throw new \ InvalidArgumentException ( 'Key "' . $ key . '" does not exist.' ) ; } return $ this -> data [ $ key ] ; }
|
Obtain the value for the given key .
|
58,324
|
protected function compileAllFiles ( ) { $ preloader = new ClassPreloader ( new PrettyPrinter , new Parser ( new Lexer ) , $ this -> getTraverser ( ) ) ; $ handle = $ preloader -> prepareOutput ( $ this -> getContainer ( ) -> getCompiledPath ( ) ) ; foreach ( $ this -> getAllFiles ( ) as $ file ) { try { fwrite ( $ handle , $ preloader -> getCode ( $ file , false ) . "\n" ) ; } catch ( SkipFileException $ ex ) { } } fclose ( $ handle ) ; }
|
compile all files for the better performance
|
58,325
|
protected function getTraverser ( ) { $ traverser = new NodeTraverser ( ) ; $ traverser -> addVisitor ( new DirVisitor ( true ) ) ; $ traverser -> addVisitor ( new FileVisitor ( true ) ) ; return $ traverser ; }
|
Get the node traverser used by the command .
|
58,326
|
protected function getAllFiles ( ) { $ core = require __DIR__ . '/Optimize/core.php' ; $ proivers = config ( 'compile.providers' ) ; $ aliases = config ( 'compile.aliases' ) ; $ files = array_merge ( $ core , $ proivers , $ aliases ) ; return $ files ; }
|
compile all files
|
58,327
|
public function query ( $ parent , array $ parameters , array $ opts = [ ] , array $ ctor = [ ] ) { return $ this -> adapter -> query ( $ parent , $ parameters , $ opts , $ ctor ) ; }
|
Query multiple models in an Adapter - independent way .
|
58,328
|
public function save ( ) { if ( $ this -> isNew ( ) ) { return $ this -> adapter -> create ( $ this ) ; } else { return $ this -> adapter -> update ( $ this ) ; } }
|
Persist this model back to whatever storage Adapter it was constructed with .
|
58,329
|
private function export ( ) { $ exported = new StdClass ; foreach ( $ this as $ name => $ field ) { if ( ( new ReflectionProperty ( $ this , $ name ) ) -> isPublic ( ) ) { if ( is_object ( $ field ) ) { $ traits = class_uses ( $ field ) ; if ( isset ( $ traits [ 'Ornament\Model' ] ) || isset ( $ traits [ 'Ornament\JsonModel' ] ) ) { $ exported -> $ name = $ field -> getPrimaryKey ( ) ; } else { $ exported -> $ name = "$field" ; } } else { $ exported -> $ name = $ field ; } } } return $ exported ; }
|
Internal helper method to export the model s public properties .
|
58,330
|
public function generate_schema ( ) { $ schema = "CREATE TABLE `" . $ this -> name . "` (\n" ; for ( $ i = 0 ; $ i < count ( $ this -> details ) ; $ i ++ ) { if ( ! isset ( $ this -> details [ $ i ] [ 'options' ] ) ) { $ this -> details [ $ i ] [ 'options' ] = array ( ) ; } $ schema .= "`" . $ this -> details [ $ i ] [ 'name' ] . "` " ; $ schema .= $ this -> type ( $ this -> details [ $ i ] ) ; $ schema .= $ this -> options ( $ this -> details [ $ i ] [ 'options' ] ) ; $ schema .= ",\n" ; } $ schema .= $ this -> table_keys ( ) ; $ schema .= ')' ; $ schema .= $ this -> engine ( ) ; return $ schema ; }
|
Generate schema for a table . Makes files and returns text in api format
|
58,331
|
function signUp ( ) { if ( isset ( $ _POST [ 'data' ] ) && trim ( $ _POST [ 'data' ] ) !== '' ) { $ private = file_get_contents ( _CONFIG . 'Key/private.key' ) ; $ key = json_decode ( $ _POST [ 'data' ] ) ; $ key = base64_decode ( $ key -> enc ) ; if ( ! openssl_private_decrypt ( $ key , $ key , openssl_pkey_get_private ( $ private ) ) ) { Ajax :: send ( [ 'error' => 'Confira seu Login ou Senha!' ] ) ; } $ key = json_decode ( $ key ) ; $ user = User :: this ( ) ; $ user -> login ( $ key -> login , $ key -> passw ) ; if ( $ user -> get ( 'login' ) ) { $ user -> saveToken ( $ key -> token ) ; $ userdata = json_encode ( [ 'name' => $ user -> get ( 'name' ) , 'id' => $ user -> get ( 'id' ) , 'level' => $ user -> get ( 'level' ) ] ) ; $ resumo = ( new Model \ Xlog ) -> resumo ( $ user -> get ( 'id' ) ) ; Aes :: size ( 256 ) ; $ key = Aes :: enc ( json_encode ( [ 'user' => $ userdata , 'token' => $ key -> token , 'resumo' => $ resumo ] ) , $ key -> token ) ; Ajax :: send ( [ 'error' => false , 'key' => $ key ] ) ; } } Ajax :: send ( [ 'error' => 'Confira seu Login ou Senha!' ] ) ; }
|
Retorna o0s dados encriptados por AES com o Token como Sincrono Key
|
58,332
|
function access ( ) { $ data [ 'agent' ] = $ _SERVER [ 'HTTP_USER_AGENT' ] ; $ data [ 'ip' ] = $ _SERVER [ 'REMOTE_ADDR' ] ; $ data [ 'method' ] = $ _SERVER [ 'REQUEST_METHOD' ] ; $ data [ 'uri' ] = $ _SERVER [ 'REQUEST_URI' ] ; $ data [ 'data' ] = date ( 'Y-m-d H:i:s' ) ; ( new Model \ Xlog ) -> setAccessData ( $ data ) ; }
|
Escrevendo dados de acesso no banco de dados
|
58,333
|
public function tLog ( string $ level , string $ message , array $ context = [ ] ) { $ logtag = $ this -> getLogTag ( ) ; if ( is_array ( $ message ) || is_object ( $ message ) ) { $ message = print_r ( $ message , true ) ; } $ this -> log ( $ level , "[{time}] [{$logtag}] " . $ message , $ context ) ; }
|
Log tagged message
|
58,334
|
public function dispatch ( ... $ params ) { $ allowedMethods = $ this -> getAllowedMethods ( ) ; if ( $ allowedMethods !== null && ! in_array ( $ this -> request -> getMethod ( ) , $ allowedMethods ) ) { } $ apiMethod = $ this -> route -> getValue ( 'api_method' , 'list' ) ; return call_user_func_array ( array ( $ this , $ apiMethod ) , $ params ) ; }
|
Dispatch the API routes .
|
58,335
|
public function findByModule ( ModuleInterface $ module = null , array $ orderBy = null , $ limit = null , $ offset = null ) { $ criteria = [ ] ; if ( $ this -> isModular ( $ module ) ) { $ criteria [ 'module' ] = $ module ; } return $ this -> findBy ( $ criteria , $ orderBy , $ limit , $ offset ) ; }
|
Find entities by a Module instance .
|
58,336
|
private function queryFirstDate ( $ assetTypeCode ) { $ query = $ this -> qbGetFirstDate -> build ( ) ; $ bind = [ $ this -> qbGetFirstDate :: BND_ASSET_TYPE_CODE => $ assetTypeCode ] ; $ conn = $ query -> getConnection ( ) ; $ result = $ conn -> fetchOne ( $ query , $ bind ) ; return $ result ; }
|
Get applied date for the first transaction fir the given asset type .
|
58,337
|
public function createFromArray ( $ class , array $ attributes ) { $ entity = new $ class ( ) ; foreach ( $ attributes as $ name => $ value ) { if ( property_exists ( $ entity , $ name ) ) { $ methodName = $ this -> getSetterName ( $ entity , $ name ) ; if ( $ methodName ) { $ entity -> { $ methodName } ( $ value ) ; } else { throw new InvalidPropertyException ( 'Add/Setter method for property ' . $ name . ' not found' ) ; } } } return $ entity ; }
|
Create entity and assign entity properties using an array
|
58,338
|
public function findByIssue ( $ issueId ) { $ queryBuilder = $ this -> getQueryBuilder ( ) ; $ queryBuilder -> leftJoin ( 'p.issues' , 'i' ) ; $ this -> addCriteria ( $ queryBuilder , [ 'i.id' => $ issueId ] ) ; return $ queryBuilder -> getQuery ( ) -> getResult ( ) ; }
|
Finds all the repositories of issue id given .
|
58,339
|
protected function a2k ( & $ dest , $ orig , $ currentKey ) { if ( is_array ( $ orig ) && ( count ( $ orig ) > 0 ) ) { foreach ( $ orig as $ key => $ value ) { if ( is_array ( $ value ) ) { $ this -> a2k ( $ dest , $ value , ( $ currentKey ? $ currentKey . '.' : '' ) . $ key ) ; } else { $ dest [ ( $ currentKey ? $ currentKey . '.' : '' ) . $ key ] = $ value ; } } } }
|
associative array indexed to dimensional associative array of keys
|
58,340
|
protected function getYamlAsArray ( $ file ) { if ( file_exists ( $ file ) ) { $ content = Yaml :: parse ( file_get_contents ( $ file ) ) ; $ result = array ( ) ; $ this -> a2k ( $ result , $ content , '' ) ; return $ result ; } else { return array ( ) ; } }
|
Reads a Yaml file and process the keys and returns as a associative indexed array
|
58,341
|
protected function k2a ( $ orig ) { $ result = array ( ) ; foreach ( $ orig as $ key => $ value ) { if ( $ value === null ) { } else { $ keys = explode ( '.' , $ key ) ; $ node = $ value ; for ( $ i = count ( $ keys ) ; $ i > 0 ; $ i -- ) { $ k = $ keys [ $ i - 1 ] ; $ node = array ( $ k => $ node ) ; } $ result = array_merge_recursive ( $ result , $ node ) ; } } return $ result ; }
|
dimensional associative array of keys to associative array indexed
|
58,342
|
public function setLogDir ( $ logDir ) { $ logDir = trim ( $ logDir ) ; if ( ! file_exists ( $ logDir ) || ! is_writable ( $ logDir ) ) { throw new \ InvalidArgumentException ( "Invalid log directory!" ) ; } $ this -> _logDir = $ logDir ; }
|
Setter for log dir
|
58,343
|
public function logException ( \ Exception $ exception , $ prefix = "Exception thrown" ) { $ class = new \ ReflectionClass ( $ exception ) ; $ this -> logger -> critical ( "$prefix [{$class->getName()}] {$exception->getMessage()} on line {$exception->getLine()} of {$exception->getFile()}\n" ) ; $ this -> logger -> debug ( "Debug trace for exception: {$exception->getTraceAsString()}" ) ; }
|
Logs any exceptions that are thrown by running jobs .
|
58,344
|
private function runJob ( $ job ) { try { $ this -> logger -> notice ( "Job #{$this->currentJobId} [{$job->getName()}] started." ) ; $ status = $ this -> broker -> getStatus ( $ job -> getId ( ) ) ; $ status [ 'status' ] = Job :: STATUS_RUNNING ; $ status [ 'started' ] = date ( DATE_RFC3339_EXTENDED ) ; $ this -> broker -> setStatus ( $ job -> getId ( ) , $ status ) ; $ job -> setup ( ) ; $ response = $ job -> go ( ) ; $ job -> tearDown ( ) ; $ status [ 'status' ] = Job :: STATUS_FINISHED ; $ status [ 'finished' ] = date ( DATE_RFC3339_EXTENDED ) ; $ status [ 'response' ] = $ response ; $ this -> broker -> setStatus ( $ job -> getId ( ) , $ status ) ; $ this -> logger -> notice ( "Job #{$this->currentJobId} [{$job->getName()}] finished." ) ; } catch ( \ Exception $ e ) { $ status [ 'status' ] = Job :: STATUS_FAILED ; $ status [ 'failed' ] = date ( DATE_RFC3339_EXTENDED ) ; $ this -> broker -> setStatus ( $ job -> getId ( ) , $ status ) ; $ this -> logException ( $ e , "Job #{$this->currentJobId} [{$job->getName()}] Exception" ) ; $ this -> logger -> alert ( "Job #{$this->currentJobId} [{$job->getName()}] died." ) ; } }
|
Actually run a job and log any exceptions or status messages .
|
58,345
|
private function executeJob ( Job $ job ) { $ this -> currentJobId = $ job -> getId ( ) ; $ job -> setLogger ( $ this -> logger ) ; $ this -> logger -> notice ( "Starting job #" . $ this -> currentJobId ) ; if ( ! function_exists ( 'pcntl_fork' ) ) { $ this -> runJob ( $ job ) ; return ; } $ pid = pcntl_fork ( ) ; if ( $ pid ) { pcntl_wait ( $ status ) ; } else { $ this -> runJob ( $ job ) ; die ( ) ; } }
|
Fork off this process and wait while job is executed .
|
58,346
|
public function mainLoop ( ) { $ bootstrap = $ this -> config -> get ( 'bootstrap' ) ; if ( $ bootstrap ) { ( function ( ) { require $ this -> config -> get ( 'bootstrap' ) ; } ) ( ) ; } $ this -> logger -> info ( "Ajumamoro" ) ; set_error_handler ( function ( $ no , $ message , $ file , $ line ) { $ this -> logger -> error ( "Job #{$this->currentJobId} Error: $message on line $line of $file" ) ; } , E_WARNING ) ; $ delay = $ this -> config -> get ( 'delay' , 200 ) ; do { $ job = $ this -> getNextJob ( ) ; if ( $ job !== false ) { $ this -> executeJob ( $ job ) ; } else { usleep ( $ delay ) ; } } while ( true ) ; }
|
The runners main loop that waits on the broker for jobs .
|
58,347
|
public function getNextJob ( ) { $ jobInfo = $ this -> broker -> get ( ) ; if ( ! class_exists ( $ jobInfo [ 'class' ] ) ) { $ this -> logger -> error ( "Class {$jobInfo['class']} for scheduled job not found" ) ; return false ; } $ job = unserialize ( $ jobInfo [ 'object' ] ) ; if ( is_object ( $ job ) && is_a ( $ job , '\ajumamoro\Job' ) ) { $ job -> setId ( $ jobInfo [ 'id' ] ) ; return $ job ; } else { $ this -> logger -> error ( "Scheduled job is not of type \\ajumamoro\\Job" ) ; return false ; } }
|
Get the next job from the broker if any exists . Ths function actuall polls the broker for any pending jobs to be executed .
|
58,348
|
public function render ( ) { $ vars = [ 'menu' => $ this , 'items' => $ this -> get ( 'root' ) -> getChildren ( ) ] ; $ rendered = $ this -> viewFactory -> make ( $ this -> view ) -> with ( $ vars ) -> render ( ) ; return $ rendered ; }
|
Renders the menu using the defined view
|
58,349
|
public function add ( $ id , $ value , $ parent = 'root' , array $ meta = [ ] , array $ attributes = [ ] ) { $ node = new Node ( $ id , $ this , $ value , $ meta , $ attributes ) ; if ( ! is_null ( $ parent ) and $ this -> items -> has ( $ parent ) ) { $ parentNode = $ this -> items -> get ( $ parent ) ; $ parentNode -> addChild ( $ node ) ; $ node -> setMeta ( 'data-parent' , $ parent ) ; } $ this -> items -> put ( $ id , $ node ) ; return $ node ; }
|
Add a menu item
|
58,350
|
public function getBreadcrumbToHref ( $ href ) { $ item = $ this -> findItemByHref ( $ href ) ; if ( $ item ) { return $ this -> getBreadcrumbTo ( $ item ) ; } else { return [ ] ; } }
|
Get breadcrumbs to the Node that has the href
|
58,351
|
public static function get ( $ path , array $ config = array ( ) , $ area = null ) { return static :: instance ( $ area ) -> get_handler ( $ path , $ config ) ; }
|
File & directory objects factory
|
58,352
|
public static function get_url ( $ path , array $ config = array ( ) , $ area = null ) { return static :: get ( $ path , $ config , $ area ) -> get_url ( ) ; }
|
Get the url .
|
58,353
|
public static function exists ( $ path , $ area = null ) { $ path = rtrim ( static :: instance ( $ area ) -> get_path ( $ path ) , '\\/' ) ; while ( $ path and is_link ( $ path ) ) { $ path = readlink ( $ path ) ; } return is_file ( $ path ) ; }
|
Check for file existence
|
58,354
|
public static function create_dir ( $ basepath , $ name , $ chmod = null , $ area = null ) { $ basepath = rtrim ( static :: instance ( $ area ) -> get_path ( $ basepath ) , '\\/' ) . DS ; $ new_dir = static :: instance ( $ area ) -> get_path ( $ basepath . trim ( $ name , '\\/' ) ) ; is_null ( $ chmod ) and $ chmod = \ Config :: get ( 'file.chmod.folders' , 0777 ) ; if ( ! is_dir ( $ basepath ) or ! is_writable ( $ basepath ) ) { throw new \ InvalidPathException ( 'Invalid basepath: "' . $ basepath . '", cannot create directory at this location.' ) ; } elseif ( is_dir ( $ new_dir ) ) { throw new \ FileAccessException ( 'Directory: "' . $ new_dir . '" exists already, cannot be created.' ) ; } $ new_dir = substr ( str_replace ( array ( '\\' , '/' ) , DS , $ new_dir ) , strlen ( $ basepath ) ) ; $ basepath = rtrim ( $ basepath , DS ) ; foreach ( explode ( DS , $ new_dir ) as $ dir ) { $ basepath .= DS . $ dir ; if ( ! is_dir ( $ basepath ) ) { try { if ( ! mkdir ( $ basepath ) ) { return false ; } chmod ( $ basepath , $ chmod ) ; } catch ( \ PHPErrorException $ e ) { return false ; } } } return true ; }
|
Create an empty directory
|
58,355
|
public static function get_permissions ( $ path , $ area = null ) { $ path = static :: instance ( $ area ) -> get_path ( $ path ) ; if ( ! file_exists ( $ path ) ) { throw new \ InvalidPathException ( 'Path: "' . $ path . '" is not a directory or a file, cannot get permissions.' ) ; } return substr ( sprintf ( '%o' , fileperms ( $ path ) ) , - 4 ) ; }
|
Get the octal permissions for a file or directory
|
58,356
|
public static function get_time ( $ path , $ type = 'modified' , $ area = null ) { $ path = static :: instance ( $ area ) -> get_path ( $ path ) ; if ( ! file_exists ( $ path ) ) { throw new \ InvalidPathException ( 'Path: "' . $ path . '" is not a directory or a file, cannot get creation timestamp.' ) ; } if ( $ type === 'modified' ) { return filemtime ( $ path ) ; } elseif ( $ type === 'created' ) { return filectime ( $ path ) ; } else { throw new \ UnexpectedValueException ( 'File::time $type must be "modified" or "created".' ) ; } }
|
Get a file s or directory s created or modified timestamp .
|
58,357
|
public static function rename ( $ path , $ new_path , $ source_area = null , $ target_area = null ) { $ path = static :: instance ( $ source_area ) -> get_path ( $ path ) ; $ new_path = static :: instance ( $ target_area ? : $ source_area ) -> get_path ( $ new_path ) ; return rename ( $ path , $ new_path ) ; }
|
Rename directory or file
|
58,358
|
public static function symlink ( $ path , $ link_path , $ is_file = true , $ area = null ) { $ path = rtrim ( static :: instance ( $ area ) -> get_path ( $ path ) , '\\/' ) ; $ link_path = rtrim ( static :: instance ( $ area ) -> get_path ( $ link_path ) , '\\/' ) ; if ( $ is_file and ! is_file ( $ path ) ) { throw new \ InvalidPathException ( 'Cannot symlink: given file: "' . $ path . '" does not exist.' ) ; } elseif ( ! $ is_file and ! is_dir ( $ path ) ) { throw new \ InvalidPathException ( 'Cannot symlink: given directory: "' . $ path . '" does not exist.' ) ; } elseif ( file_exists ( $ link_path ) ) { throw new \ FileAccessException ( 'Cannot symlink: link: "' . $ link_path . '" already exists.' ) ; } return symlink ( $ path , $ link_path ) ; }
|
Create a new symlink
|
58,359
|
public static function close_file ( $ resource , $ area = null ) { if ( static :: instance ( $ area ) -> use_locks ( ) ) { flock ( $ resource , LOCK_UN ) ; } fclose ( $ resource ) ; }
|
Close file resource & unlock
|
58,360
|
public static function file_info ( $ path , $ area = null ) { $ info = array ( 'original' => $ path , 'realpath' => '' , 'dirname' => '' , 'basename' => '' , 'filename' => '' , 'extension' => '' , 'mimetype' => '' , 'charset' => '' , 'size' => 0 , 'permissions' => '' , 'time_created' => '' , 'time_modified' => '' , ) ; if ( ! $ info [ 'realpath' ] = static :: instance ( $ area ) -> get_path ( $ path ) or ! is_file ( $ info [ 'realpath' ] ) ) { throw new \ InvalidPathException ( 'Filename given is not a valid file.' ) ; } $ info = array_merge ( $ info , pathinfo ( $ info [ 'realpath' ] ) ) ; if ( ! $ fileinfo = new \ finfo ( FILEINFO_MIME , \ Config :: get ( 'file.magic_file' , null ) ) ) { throw new \ InvalidArgumentException ( 'Can not retrieve information about this file.' ) ; } $ fileinfo = explode ( ';' , $ fileinfo -> file ( $ info [ 'realpath' ] ) ) ; $ info [ 'mimetype' ] = isset ( $ fileinfo [ 0 ] ) ? $ fileinfo [ 0 ] : 'application/octet-stream' ; if ( isset ( $ fileinfo [ 1 ] ) ) { $ fileinfo = explode ( '=' , $ fileinfo [ 1 ] ) ; $ info [ 'charset' ] = isset ( $ fileinfo [ 1 ] ) ? $ fileinfo [ 1 ] : '' ; } $ info [ 'size' ] = static :: get_size ( $ info [ 'realpath' ] , $ area ) ; $ info [ 'permissions' ] = static :: get_permissions ( $ info [ 'realpath' ] , $ area ) ; $ info [ 'time_created' ] = static :: get_time ( $ info [ 'realpath' ] , $ type = 'created' , $ area ) ; $ info [ 'time_modified' ] = static :: get_time ( $ info [ 'realpath' ] , $ type = 'modified' , $ area ) ; return $ info ; }
|
Get detailed information about a file
|
58,361
|
public static function strip ( $ text = '' , array $ allowedTags = [ ] ) : string { $ text = \ htmlspecialchars_decode ( ( string ) $ text , ENT_COMPAT | ENT_HTML5 ) ; foreach ( $ allowedTags as $ tag ) { $ text = \ preg_replace ( '|<(/?' . $ tag . '\ ?/?)>|i' , '{{{{\\1}}}}' , $ text ) ; $ text = \ preg_replace ( '|<(' . $ tag . ' [^>]+)>|i' , '{{{{\\1}}}}' , $ text ) ; } $ text = \ preg_replace ( '/<[^>]+>/' , ' ' , $ text ) ; foreach ( $ allowedTags as $ tag ) { $ text = \ preg_replace ( '|{{{{(/?' . $ tag . '\ ?/?)}}}}|i' , '<\\1>' , $ text ) ; $ text = \ preg_replace ( '|{{{{(' . $ tag . ' [^}]+)}}}}|i' , '<\\1>' , $ text ) ; } $ text = \ preg_replace ( '/\s+/' , ' ' , $ text ) ; return \ trim ( $ text ) ; }
|
Strips tags from text . Preserves allowed tags .
|
58,362
|
private function source ( ) { $ source_url = 'https://www.iso.org/obp/ui/' ; file_get_contents ( $ source_url ) ; foreach ( $ http_response_header as $ header ) { if ( substr ( $ header , 0 , 10 ) != 'Set-Cookie' ) { continue ; } $ cookie = explode ( ';' , substr ( $ header , 12 ) ) [ 0 ] ; } $ resource_info = file_get_contents ( $ source_url , false , stream_context_create ( [ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\nCookie: {$cookie}\r\n" , 'method' => 'POST' , 'content' => 'v-browserDetails=1&v-loc=https%3A%2F%2Fwww.iso.org%2Fobp%2Fui%2F%23search' ] , ] ) ) ; $ csrf_token = json_decode ( json_decode ( $ resource_info ) -> uidl ) -> { 'Vaadin-Security-Key' } ; $ rpc_calls = [ '"rpc":[["0","com.vaadin.shared.ui.ui.UIServerRpc","resize",["448","1370","1370","448"]],["62","com.vaadin.ui.JavaScript$JavaScriptCallbackRpc","call",["onCaptureSessionNotFound",[null]]]], "syncId":1' , '"rpc":[["18","v","v",["selected",["S",["6"]]]]], "syncId":2' , '"rpc":[["24","com.vaadin.shared.communication.FieldRpc$FocusAndBlurServerRpc","focus",[]]], "syncId":3' , '"rpc":[["24","com.vaadin.shared.ui.button.ButtonServerRpc","click",[{"metaKey":false, "type":"1", "button":"LEFT", "relativeY":"19", "relativeX":"9", "clientX":"1079", "clientY":"309", "ctrlKey":false, "shiftKey":false, "altKey":false}]]], "syncId":4' , '"rpc":[["85","com.vaadin.shared.ui.csslayout.CssLayoutServerRpc","layoutClick",[{"metaKey":false, "type":"8", "button":"LEFT", "relativeY":"14", "relativeX":"105", "clientX":"117", "clientY":"375", "ctrlKey":false, "shiftKey":false, "altKey":false},"86"]]], "syncId":5' , '"rpc":[["53","v","v",["selected",["S",["16"]]]]], "syncId":6' ] ; $ source_url = 'https://www.iso.org/obp/ui/UIDL/?v-uiId=0' ; foreach ( $ rpc_calls as $ rpc_call ) { $ json = '{ "csrfToken":"' . $ csrf_token . '", ' . $ rpc_call . ' }' ; $ result = file_get_contents ( $ source_url , false , stream_context_create ( [ 'http' => [ 'header' => "Content-type: application/json;charset=UTF-8\r\nCookie: {$cookie}\r\n" , 'method' => 'POST' , 'content' => $ json , ] , ] ) ) ; } return $ result ; }
|
Return the raw data source .
|
58,363
|
public function build ( ) { $ countries = [ ] ; $ alpha3_index = [ ] ; $ numeric3_index = [ ] ; $ source = json_decode ( substr ( $ this -> source ( ) , 8 ) ) [ 0 ] ; foreach ( $ source -> changes [ 1 ] [ 2 ] [ 2 ] as $ index => $ country ) { if ( $ index < 2 ) { continue ; } $ countries [ $ country [ 4 ] ] = [ 'name' => $ source -> state -> { $ country [ 2 ] [ 1 ] -> id } -> caption , 'alpha2' => $ country [ 4 ] , 'alpha3' => $ country [ 5 ] , 'numeric3' => $ country [ 6 ] , ] ; $ alpha3_index [ $ country [ 5 ] ] = $ country [ 4 ] ; $ numeric3_index [ $ country [ 6 ] ] = $ country [ 4 ] ; } $ template = file_get_contents ( $ this -> templateFile ) ; $ template = str_replace ( '/* countries */' , '= ' . $ this -> encoder -> encode ( $ countries , [ 'array.base' => 4 ] ) , $ template ) ; $ template = str_replace ( '/* alpha3_index */' , '= ' . $ this -> encoder -> encode ( $ alpha3_index , [ 'array.base' => 4 ] ) , $ template ) ; $ template = str_replace ( '/* numeric3_index */' , '= ' . $ this -> encoder -> encode ( $ numeric3_index , [ 'array.base' => 4 ] ) , $ template ) ; file_put_contents ( $ this -> outputFile , $ template ) ; }
|
Generate the class and save it to the filesystem .
|
58,364
|
public static function imageFile ( $ dir = null , $ width = 800 , $ height = 600 , $ format = 'png' , $ fullPath = true , $ text = null , $ textColor = null , $ backgroundColor = null , $ fontPath = null ) { $ dir = is_null ( $ dir ) ? sys_get_temp_dir ( ) : $ dir ; if ( ! is_dir ( $ dir ) || ! is_writable ( $ dir ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cannot write to directory "%s"' , $ dir ) ) ; } $ name = md5 ( uniqid ( empty ( $ _SERVER [ 'SERVER_ADDR' ] ) ? '' : $ _SERVER [ 'SERVER_ADDR' ] , true ) ) ; $ filename = implode ( '.' , [ $ name , $ format ] ) ; $ filepath = $ dir . DIRECTORY_SEPARATOR . $ filename ; if ( $ text === null ) { $ text = static :: DEFAULT_TEXT_FORMAT ; } if ( $ textColor === null ) { $ textColor = static :: DEFAULT_TEXT_COLOR ; } if ( $ backgroundColor === null ) { $ backgroundColor = static :: randomElement ( static :: $ colors ) ; } $ textColor = static :: hexColor ( $ textColor ) ; $ backgroundColor = static :: hexColor ( $ backgroundColor ) ; $ maxTextWidth = floor ( $ width - ( $ width * self :: TEXT_PAD_MULTIPLIER ) ) ; $ formattedText = str_replace ( [ '%width%' , '%height%' , '%format%' , '%file%' , '%filepath%' , '%color%' , '%bgcolor%' ] , [ $ width , $ height , $ format , $ filename , $ filepath , $ textColor , $ backgroundColor ] , $ text ) ; $ imanee = new \ Imanee \ Imanee ( ) ; $ imanee -> newImage ( $ width , $ height , $ backgroundColor ) ; $ imanee -> getDrawer ( ) -> setFontColor ( $ textColor ) -> setTextAlign ( \ Imanee \ Drawer :: TEXT_ALIGN_LEFT ) ; if ( $ fontPath !== null ) { $ imanee -> getDrawer ( ) -> setFont ( $ fontPath ) ; } $ imanee -> setFormat ( $ format ) -> placeText ( $ formattedText , \ Imanee \ Imanee :: IM_POS_MID_CENTER , $ maxTextWidth ) -> write ( $ filepath , static :: JPEG_QUALITY ) ; return $ fullPath ? $ filepath : $ filename ; }
|
Generate a new image to disk and return its location .
|
58,365
|
private function invoke ( $ fn , $ params = [ ] ) { if ( is_callable ( $ fn ) ) { call_user_func_array ( $ fn , $ params ) ; } elseif ( preg_match ( '/@/' , $ fn ) !== false ) { list ( $ controller , $ method ) = explode ( '@' , $ fn ) ; if ( class_exists ( $ controller ) ) { if ( call_user_func_array ( array ( new $ controller ( ) , $ method ) , $ params ) === false ) { if ( forward_static_call_array ( array ( $ controller , $ method ) , $ params ) === false ) ; } } } }
|
Call the function
|
58,366
|
public function route ( $ methods , string $ pattern , $ callback ) { $ methods = explode ( "|" , $ methods ) ; if ( empty ( $ methods ) ) throw new \ RuntimeException ( 'Invalid methods provided' ) ; $ methods = $ this -> validateMethods ( $ methods ) ; foreach ( $ methods as $ method ) $ this -> routes [ $ method ] [ ] = [ "pattern" => trim ( $ pattern , '/' ) , "callback" => $ callback , ] ; return $ this ; }
|
Store a route and a handling function to be executed when accessed using one of the specified methods .
|
58,367
|
public function getOptionsResolver ( ) { if ( null === $ this -> optionsResolver ) { if ( null !== $ this -> parent ) { $ this -> optionsResolver = clone $ this -> parent -> getOptionsResolver ( ) ; } else { $ this -> optionsResolver = new OptionsResolver ( ) ; } $ this -> innerType -> setDefaultOptions ( $ this -> optionsResolver ) ; } return $ this -> optionsResolver ; }
|
Returns the configured options resolver used for this type .
|
58,368
|
public function setAuthors ( $ post ) { $ username = $ post -> getAuthor ( ) -> getUsername ( ) ; if ( in_array ( $ username , array_keys ( $ this -> config [ 'authors' ] ) ) ) { if ( in_array ( $ username , $ this -> authorsName ) ) { $ this -> authors [ $ username ] -> setPost ( $ post ) ; } else { $ this -> authors [ $ username ] = new Author ( $ username , $ this -> config [ 'authors' ] [ $ username ] [ 'name' ] , $ this -> config [ 'authors' ] [ $ username ] [ 'email' ] , $ this -> config [ 'authors' ] [ $ username ] [ 'facebook' ] , $ this -> config [ 'authors' ] [ $ username ] [ 'twitter' ] , $ this -> config [ 'authors' ] [ $ username ] [ 'github' ] ) ; $ this -> authors [ $ username ] -> setPost ( $ post ) ; $ this -> authorsName [ ] = $ username ; } } }
|
Set Posts on author
|
58,369
|
public function save ( EntityInterface $ entity , array $ data = [ ] ) { $ this -> entity = $ entity ; $ query = $ this -> getUpdateQuery ( ) ; $ data = $ this -> getData ( ) ; $ save = $ this -> triggerBeforeSave ( $ query , $ entity , $ data ) ; $ query -> set ( $ save -> params ) -> execute ( ) ; $ lastId = $ query -> getAdapter ( ) -> getLastInsertId ( ) ; if ( $ lastId ) { $ entity -> setId ( $ lastId ) ; } $ this -> triggerAfterSave ( $ save , $ entity ) ; $ this -> registerEntity ( $ entity ) ; return $ this ; }
|
Saves current entity object to database
|
58,370
|
public function delete ( EntityInterface $ entity ) { $ this -> entity = $ entity ; $ primaryKey = $ this -> getDescriptor ( ) -> getPrimaryKey ( ) -> getName ( ) ; $ table = $ this -> getDescriptor ( ) -> getTableName ( ) ; $ sql = Sql :: createSql ( $ this -> getAdapter ( ) ) ; $ this -> triggerBeforeDelete ( $ entity ) ; $ this -> setUpdateCriteria ( $ sql -> delete ( $ table ) , $ primaryKey , $ table ) -> execute ( ) ; $ this -> triggerAfterDelete ( $ entity ) ; $ this -> removeEntity ( $ entity ) ; return $ this ; }
|
Deletes current entity from database
|
58,371
|
protected function setUpdateCriteria ( Sql \ SqlInterface $ query , $ primaryKey , $ table ) { $ key = "{$table}.{$primaryKey} = :id" ; $ query -> where ( [ $ key => [ ':id' => $ this -> entity -> { $ primaryKey } ] ] ) ; return $ query ; }
|
Adds the update criteria for an update query
|
58,372
|
protected function getData ( ) { $ data = [ ] ; $ fields = $ this -> getDescriptor ( ) -> getFields ( ) ; foreach ( $ fields as $ field ) { $ data [ $ field -> getField ( ) ] = $ this -> entity -> { $ field -> getName ( ) } ; } return $ data ; }
|
Gets data to be used in queries
|
58,373
|
public function createFrom ( $ data ) { if ( $ data instanceof RecordList ) { return $ this -> createMultiple ( $ data ) ; } return null == $ data ? null : $ this -> createSingle ( $ data ) ; }
|
Creates an entity object from provided data
|
58,374
|
protected function createSingle ( array $ source ) { $ data = [ ] ; foreach ( $ this -> getDescriptor ( ) -> getFields ( ) as $ field ) { if ( array_key_exists ( $ field -> getField ( ) , $ source ) ) { $ data [ $ field -> getName ( ) ] = $ source [ $ field -> getField ( ) ] ; } } $ class = $ this -> getDescriptor ( ) -> className ( ) ; return new $ class ( $ data ) ; }
|
Creates an entity for provided row array
|
58,375
|
protected function createMultiple ( RecordList $ source ) { $ data = [ ] ; foreach ( $ source as $ item ) { $ data [ ] = $ this -> createSingle ( $ item ) ; } return new EntityCollection ( $ this -> getEntityClassName ( ) , $ data ) ; }
|
Creates an entity collection for provided record list
|
58,376
|
protected function registerEntity ( EntityInterface $ entity ) { Orm :: getRepository ( $ this -> getEntityClassName ( ) ) -> getIdentityMap ( ) -> set ( $ entity ) ; return $ this ; }
|
Sets the entity in the identity map of its repository .
|
58,377
|
protected function removeEntity ( EntityInterface $ entity ) { Orm :: getRepository ( $ this -> getEntityClassName ( ) ) -> getIdentityMap ( ) -> remove ( $ entity ) ; }
|
Removes the entity from the identity map of its repository .
|
58,378
|
public function setLine ( $ line ) { if ( ! is_string ( $ line ) ) { throw new InvalidArgumentException ( 'Expected a string, but got ' . gettype ( $ line ) ) ; } $ this -> line = $ line ; }
|
Set the line .
|
58,379
|
public function url ( string $ url , ? array $ schemas = null , ? string $ defaultSchema = null ) : bool { if ( ! $ this -> hasSchema ( $ url ) && ! empty ( $ defaultSchema ) ) { $ defaultSchema = $ this -> trimSchema ( $ defaultSchema ) ; if ( ! empty ( $ defaultSchema ) ) { $ url = "$defaultSchema://{$this->trimURL($url)}" ; } } if ( empty ( $ schemas ) ) { return ( bool ) filter_var ( $ url , FILTER_VALIDATE_URL ) ; } foreach ( $ schemas as $ schema ) { $ schema = $ this -> trimSchema ( $ schema ) ; if ( empty ( $ schema ) || ! $ this -> containsSchema ( $ url , $ schema ) ) { continue ; } return ( bool ) filter_var ( $ url , FILTER_VALIDATE_URL ) ; } return false ; }
|
Check if URL is valid .
|
58,380
|
public static function getEmail ( $ config = null , $ reset = true , $ className = null ) { if ( empty ( $ config ) ) { $ config = Common :: read ( 'Email.config' , 'default' ) ; } if ( empty ( $ className ) ) { $ className = Common :: read ( 'Email.classname' , 'CakeEmail' ) ; } list ( $ plugin , $ className ) = pluginSplit ( $ className , true ) ; $ key = ucfirst ( Inflector :: camelize ( $ config ) ) . 'Email' ; if ( ! ClassRegistry :: isKeySet ( $ key ) ) { App :: uses ( $ className , $ plugin . 'Network/Email' ) ; ClassRegistry :: addObject ( $ key , new $ className ( $ config ) ) ; } $ Email = ClassRegistry :: getObject ( $ key ) ; if ( $ reset ) { $ Email -> reset ( ) -> config ( $ config ) ; } return $ Email ; }
|
Get email instance .
|
58,381
|
public static function getLog ( $ className = null ) { if ( empty ( $ className ) ) { $ className = Common :: read ( 'Log.classname' , 'CakeLog' ) ; } list ( $ plugin , $ className ) = pluginSplit ( $ className , true ) ; $ key = 'CommonLog' ; if ( ! ClassRegistry :: isKeySet ( 'CommonLog' ) ) { App :: uses ( $ className , $ plugin . 'Log' ) ; ClassRegistry :: addObject ( 'CommonLog' , new $ className ) ; } $ Log = ClassRegistry :: getObject ( 'CommonLog' ) ; return $ Log ; }
|
Get log instance .
|
58,382
|
public static function random ( $ len = 20 , $ char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ) { $ str = '' ; for ( $ ii = 0 ; $ ii < $ len ; $ ii ++ ) { $ str .= $ char [ mt_rand ( 0 , strlen ( $ char ) - 1 ) ] ; } return $ str ; }
|
Generates a random string .
|
58,383
|
public static function reader ( $ config = null , $ default = false ) { if ( empty ( $ config ) ) { $ config = array ( 'id' => 'json' , 'className' => 'JsonReader' , 'location' => 'Common.Configure' ) ; } if ( ! is_array ( $ config ) ) { $ config = array ( 'id' => $ config , 'className' => ucfirst ( $ config ) . 'Reader' , 'location' => 'Configure' ) ; } extract ( $ config ) ; if ( Configure :: configured ( $ id ) ) { throw new ConfigureException ( __d ( '_common_' , "A reader with the '%s' name already exists." , $ id ) ) ; } foreach ( array ( 'id' , 'className' , 'location' ) as $ var ) { if ( ! isset ( $ $ var ) || empty ( $ $ var ) ) { throw new ConfigureException ( __d ( '_common_' , "Reader configuration missing the '%s' key." , $ key ) ) ; } } App :: uses ( $ className , $ location ) ; Configure :: config ( $ default ? 'default' : $ id , new $ className ) ; return $ config ; }
|
Setup configuration reader .
|
58,384
|
public static function startTimer ( $ name , $ message = null ) { if ( ! Reveal :: is ( 'DebugKit.running' ) ) { return ; } App :: uses ( 'DebugTimer' , 'DebugKit.Lib' ) ; DebugTimer :: start ( $ name , $ message ) ; }
|
Starts a benchmarking timer only if DebugKit is enabled .
|
58,385
|
public static function url ( $ url ) { if ( is_array ( $ url ) || ( is_string ( $ url ) && ( preg_match ( '@^' . implode ( '|' , Common :: $ uriSchemes ) . ':@i' , $ url ) || preg_match ( '@^#@i' , $ url ) ) ) ) { return $ url ; } $ reset = Configure :: check ( 'Config.language' ) && $ lang = Configure :: read ( 'Config.language' ) ; $ parsed = Router :: parse ( $ url ) ; if ( $ reset ) Configure :: write ( 'Config.language' , $ lang ) ; if ( $ parsed === false ) { return $ url ; } if ( ! empty ( $ parsed [ 'pass' ] ) ) { $ parsed = array_merge ( $ parsed , $ parsed [ 'pass' ] ) ; unset ( $ parsed [ 'pass' ] ) ; } if ( ! empty ( $ parsed [ 'named' ] ) ) { foreach ( $ parsed [ 'named' ] as $ param => $ val ) { $ parsed [ $ param ] = $ val ; } unset ( $ parsed [ 'named' ] ) ; } if ( array_key_exists ( 'lang' , $ parsed ) && strpos ( $ url , $ parsed [ 'lang' ] ) !== 1 ) { unset ( $ parsed [ 'lang' ] ) ; } return $ parsed ; }
|
Transform CakePHP related URL strings into an array .
|
58,386
|
public static function wiki ( $ page = 'home' , $ repo = null ) { if ( empty ( $ repo ) ) { try { $ plugin = Reveal :: plugin ( Reveal :: path ( true ) ) ; } catch ( Exception $ e ) { } if ( empty ( $ plugin ) ) { throw new Exception ( ) ; } $ repo = 'gourmet/' . strtolower ( $ plugin ) ; } return sprintf ( 'https://github.com/%s/wiki/%s' , $ repo , $ page ) ; }
|
Generate plugin s wiki uri .
|
58,387
|
public function checkSecure ( ) { if ( $ this -> secure === null ) return true ; $ in_secure = isset ( $ _SERVER [ 'HTTPS' ] ) && $ _SERVER [ 'HTTPS' ] === 'on' ; return ( $ this -> secure && $ in_secure ) || ( ! $ this -> secure && ! $ in_secure ) ; }
|
checking secure setting
|
58,388
|
public function methodName2URL ( $ method ) { if ( ! $ this -> restful ) return parent :: methodName2URL ( $ method ) ; $ method = preg_replace ( '/Action$/i' , '' , $ method ) ; $ method = preg_replace ( '/^(' . self :: HTTP_METHOD_ANY . ')/i' , '' , $ method ) ; return trim ( strtolower ( preg_replace ( '/[A-Z]/' , '-\0' , $ method ) ) , '-' ) ; }
|
getFooBarZooAction to foo - bar - zoo
|
58,389
|
public function mapResult ( ResultIterator $ result ) { if ( $ result -> countRows ( ) == 0 ) return null ; $ this -> columnTypes = $ result -> getColumnTypes ( ) ; if ( $ this -> defaultClass != 'stdClass' || ! is_null ( $ this -> resultMap ) ) $ this -> buildTypeHandlerList ( ) ; return $ this -> map ( $ result -> fetchObject ( ) ) ; }
|
Returns a mapped object from a result iterator
|
58,390
|
public function getConfig ( ? string $ key = null , ? string $ subKey = null ) { if ( $ key === null ) { return $ this -> config ; } $ key = ( string ) $ key ; $ subKey = $ subKey === null ? null : ( string ) $ subKey ; if ( array_key_exists ( $ key , $ this -> config ) ) { if ( $ subKey !== null ) { return array_key_exists ( $ subKey , $ this -> config [ $ key ] ) ? $ this -> config [ $ key ] [ $ subKey ] : null ; } return $ this -> config [ $ key ] ; } return null ; }
|
Quick access to a configuration node
|
58,391
|
public function getPassword ( ) : IHashedPassword { return new class implements IHashedPassword { public function getHash ( ) : string { } public function getAlgorithm ( ) : string { } public function getCostFactor ( ) : int { } public function toArray ( ) : array { } public function hydrate ( array $ properties ) { } } ; }
|
Gets the user s hashed password .
|
58,392
|
protected function getMigrationFile ( $ name , $ path = false ) { $ path = $ path ? $ path : $ this -> migrationPath ; return $ path . DIRECTORY_SEPARATOR . $ name . '.php' ; }
|
gets path to migration file
|
58,393
|
public function actionDataDump ( $ table , $ remove = 1 ) { $ className = 'm' . gmdate ( 'ymd_His' ) . '_' . $ table . '_dump' ; if ( ! $ data = $ this -> db -> createCommand ( "SELECT * FROM {{{$table}}}" ) -> queryAll ( ) ) { throw new Exception ( "No data found" ) ; } $ columns = DbHelper :: dataColumns ( $ data ) ; $ sql = DbHelper :: insertUpdate ( $ table , $ columns , $ data ) -> getSql ( ) ; $ file = $ this -> migrationPath . DIRECTORY_SEPARATOR . $ className . '.php' ; $ content = $ this -> renderFile ( Yii :: getAlias ( $ this -> dumpTemplateFile ) , compact ( 'className' , 'remove' , 'sql' , 'table' ) ) ; file_put_contents ( $ file , $ content ) ; echo "New migration created successfully.\n" ; }
|
Generate any table data migration into
|
58,394
|
public function actionCreate ( $ name , $ module = null ) { if ( ! empty ( $ module ) ) { if ( empty ( $ this -> allMigrationPaths [ $ module ] ) ) { throw new Exception ( "Module $module does not exist or does not contains 'migrations' directory" ) ; } $ this -> migrationPath = $ this -> allMigrationPaths [ $ module ] ; } parent :: actionCreate ( $ name ) ; }
|
Creates a new migration .
|
58,395
|
protected function setModuleMigrationPaths ( $ module ) { $ paths = [ Yii :: getAlias ( '@app/runtime/tmp' ) ] ; if ( isset ( $ this -> allMigrationPaths [ $ module ] ) ) { $ paths [ $ module ] = $ this -> allMigrationPaths [ $ module ] ; } $ this -> allMigrationPaths = $ paths ; $ this -> setMigrationFiles ( ) ; }
|
Sets modules array - leaves only module migrations .
|
58,396
|
protected function compare ( array $ a , array $ b ) : ArrayDelta { $ delta = [ ] ; foreach ( $ a as $ key => $ value ) { if ( array_key_exists ( $ key , $ b ) ) { if ( is_array ( $ value ) ) { $ deltaX = self :: compare ( $ value , $ b [ $ key ] ) ; if ( count ( $ deltaX ) ) { $ delta [ $ key ] = $ deltaX ; } } else { if ( $ value != $ b [ $ key ] ) { $ delta [ $ key ] = $ value ; } } } else { $ delta [ $ key ] = $ value ; } } return $ delta ; }
|
Compute the difference of 2 arrays - multi dimensions supported
|
58,397
|
protected function getGenericPropertyReader ( ) : Closure { $ reader = function & ( $ object , $ property ) { $ value = & Closure :: bind ( function & ( ) use ( $ property ) { return $ this -> { $ property } ; } , $ object , $ object ) -> __invoke ( ) ; return $ value ; } ; return $ reader ; }
|
Returns a callback that can read private variables from object .
|
58,398
|
public function setConfig ( $ key , $ value = '' ) { if ( is_array ( $ key ) ) { $ this -> _config = array_merge ( $ this -> _config , $ key ) ; } else { $ this -> _config [ $ key ] = $ value ; } $ this -> updateConfig ( ) ; return $ this ; }
|
Set config class
|
58,399
|
public function getConfig ( $ index = '' ) { if ( $ index === '' ) { return $ this -> _config ; } if ( isset ( $ this -> _config [ $ index ] ) ) { return $ this -> _config [ $ index ] ; } return null ; }
|
get config value
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.